MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Exporting images without white borders

  • To: mathgroup at smc.vnet.net
  • Subject: [mg75265] Exporting images without white borders
  • From: "Steven T. Hatton" <hattons at globalsymmetry.com>
  • Date: Mon, 23 Apr 2007 05:35:56 -0400 (EDT)

If I import an image into a notebook and use the raster to create an image
with the same number of pixels, when I export the image it always has a
white frame around it.  If I give it PlotRange->{{0,640},{0,480}} it
reduces the size of the of the border to one pixel, but I cannot figure out
a way to get rid of the border without changing the size of the image -
which is unacceptable.

This produces a properly saved image file:
SetDirectory[dn = "~/Documents/test"];
img = Import[dn <> "/test-in.jpg"];
cntr = {640/2, 480/2};
gx = Graphics[
      img[[1]]
      , AspectRatio -> Automatic
      , ImageSize -> {640, 480}
      , PlotRange -> {{0, 640}, {0, 480}}
      ];
Export["test-out.jpg", gx, ImageSize -> {640, 480}]

This produces an image file with a 1-pixel border on the right and the
bottom:
SetDirectory[dn = "~/Documents/test"];
img = Import[dn <> "/test-in.jpg"];
cntr = {640/2, 480/2};
gx = Graphics[
      {img[[1]]}
      , AspectRatio -> Automatic
      , ImageSize -> {640, 480}
      , PlotRange -> {{0, 640}, {0, 480}}
      ];
Export["test-out.jpg", gx, ImageSize -> {640, 480}]

Why?


  • Prev by Date: Re: question
  • Next by Date: Re: Outputting to file with fixed decimal digits
  • Previous by thread: Re: Re: question (2nd)
  • Next by thread: Re: Exporting images without white borders