How to scale an image?

  • Follow


Hi,

I've written a small image viewer which basically mirrors html's "map", 
i.e. each image has a set of areas which link to other images. I'm using 
it to view pages from a street atlas which I've scanned (you click on 
the arrows that indicate on which page the map continues) and also 
photo's I've taken from street corners in a city (you click on the left 
or right side of the image to virtually turn left or right, click on the 
top of the image to advance to the next corner, click on the bottom of 
the image to turn 180�).

Since the images themselves are quite big, I'm using a scrolled canvas, 
but I'd also like to scale images to (arbitrary) sizes. I just scale the 
areas' coordinates by my rescale factor (e.g. 0.33) which works quite 
fine, but I use Image::Copy(-shrink, -subsample => 1/$scale) which does 
not work as desired as it wants to subsample using integral values, so 
if my rescale factor is 0.33, the areas and the rescaled image do not match.

How would I rescale an image using arbitrary, non-integral scaling factors?

Thanks,

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef M�llers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
0
Reply Josef 10/27/2009 9:12:57 AM

Josef Moellers wrote:
> Hi,
> 
> I've written a small image viewer which basically mirrors html's "map", 
> i.e. each image has a set of areas which link to other images. I'm using 
> it to view pages from a street atlas which I've scanned (you click on 
> the arrows that indicate on which page the map continues) and also 
> photo's I've taken from street corners in a city (you click on the left 
> or right side of the image to virtually turn left or right, click on the 
> top of the image to advance to the next corner, click on the bottom of 
> the image to turn 180�).
> 
> Since the images themselves are quite big, I'm using a scrolled canvas, 
> but I'd also like to scale images to (arbitrary) sizes. I just scale the 
> areas' coordinates by my rescale factor (e.g. 0.33) which works quite 
> fine, but I use Image::Copy(-shrink, -subsample => 1/$scale) which does 
> not work as desired as it wants to subsample using integral values, so 
> if my rescale factor is 0.33, the areas and the rescaled image do not 
> match.
> 
> How would I rescale an image using arbitrary, non-integral scaling factors?
> 
> Thanks,
> 
> Josef


External graphics libraries are the best bet for image manipulation.
Use Image::Magick scale or mogrify resize.  There is also an
Image::Resize which uses GD.
0
Reply Steve 10/27/2009 9:53:46 PM


Am Tue, 27 Oct 2009 17:53:46 -0400 schrieb Steve C:

> External graphics libraries are the best bet for image manipulation. Use
> Image::Magick scale or mogrify resize.  There is also an Image::Resize
> which uses GD.

  I've heard from others that the API of ImageMagick changes often.
In my experience ImageMagick is sometimes eating up a lot of memory and it
seems show more bugs than other image manipulation packages.

  For me Imager is working quite well. 

  Oliver

0
Reply Oliver 10/29/2009 9:38:16 PM

Oliver 'ojo' Bedford wrote:
> Am Tue, 27 Oct 2009 17:53:46 -0400 schrieb Steve C:
> 
>> External graphics libraries are the best bet for image manipulation. Use
>> Image::Magick scale or mogrify resize.  There is also an Image::Resize
>> which uses GD.
> 
>   I've heard from others that the API of ImageMagick changes often.
> In my experience ImageMagick is sometimes eating up a lot of memory and it
> seems show more bugs than other image manipulation packages.
> 
>   For me Imager is working quite well. 

Thanks for the hints. I have used Image::Magick already elsewhere (e.g. 
using Annotate to create title slides for slide-shows), but they all 
seem to be alien to Tk!
I would have to load an image, rescale it, then store it back into a 
file and the reload it using Tk::Photo. Any idea how I could load the 
image, rescale and then hand over to Tk::Photo? I know that I can use an 
in-core image if that's encoded, so I would do that (use encode_base64() 
from MIME::Base64), I'd like to avoid the store and reload.

Thanks,

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
0
Reply Josef 10/30/2009 10:39:30 AM

Am Fri, 30 Oct 2009 11:39:30 +0100 schrieb Josef Moellers:

> I would have to load an image, rescale it, then store it back into a
> file and the reload it using Tk::Photo. Any idea how I could load the
> image, rescale and then hand over to Tk::Photo? I know that I can use an
> in-core image if that's encoded, so I would do that (use encode_base64()
> from MIME::Base64), I'd like to avoid the store and reload.

  I'm using the method you describe (using encode_base64()). Something
along the lines

  $img = Imager->new;
  $img->read(file => "foo");
  $newimg = $img->scale();
  $newimg->write(data => \$inmemory);
  $mainwindow->Photo("photo", data => encode_base64($inmemory));

  Works well, although to me it feels a bit clumsy. 
Until now I haven't found a better alternative.

  Oliver

0
Reply Oliver 11/1/2009 10:55:24 AM

Oliver 'ojo' Bedford wrote:
> Am Fri, 30 Oct 2009 11:39:30 +0100 schrieb Josef Moellers:
> 
>> I would have to load an image, rescale it, then store it back into a
>> file and the reload it using Tk::Photo. Any idea how I could load the
>> image, rescale and then hand over to Tk::Photo? I know that I can use an
>> in-core image if that's encoded, so I would do that (use encode_base64()
>> from MIME::Base64), I'd like to avoid the store and reload.
> 
>   I'm using the method you describe (using encode_base64()). Something
> along the lines
> 
>   $img = Imager->new;
>   $img->read(file => "foo");
>   $newimg = $img->scale();
>   $newimg->write(data => \$inmemory);
>   $mainwindow->Photo("photo", data => encode_base64($inmemory));
> 
>   Works well, although to me it feels a bit clumsy. 
> Until now I haven't found a better alternative.

Thanks in a million. That did the trick.
Not sure if handling a 7 Megapixel image in memory is The Right Thing, 
but ... it does what I want it to do.

Josef
-- 
These are my personal views and not those of Fujitsu Technology Solutions!
Josef Möllers (Pinguinpfleger bei FTS)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://de.ts.fujitsu.com/imprint.html
0
Reply Josef 11/2/2009 9:53:06 AM

5 Replies
188 Views

(page loaded in 0.111 seconds)

Similiar Articles:













7/17/2012 10:00:02 PM


Reply: