image.read(size, file) not working

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tomf

image.read(size, file) not working

Post by tomf »

I can read images with image.read("test.jpg") without a problem. My problem however is, that when I'm using image.read("50x50", "test.jpg") the first argument (the geometry) is simply ignored. The image still has the same size as without specifing the geometry. Forcing the resize "50x50!" also has no effect.

The second problem is, that without specifing the geometry the image also has a wrong size - no matter how big the image is after reading it I get 512 columns/width by using image.columns();

Am I doing something wrong here?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: image.read(size, file) not working

Post by magick »

For the JPEG format, the size if just a hint. To get the exact size you want, use image.resize().
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image.read(size, file) not working

Post by anthony »

In fact from personal experience. the size hint will be enlarged to the next power of 2 and the image read will be between that size and the next power higher still!

For example a size hint of 200x100 will become 256x128 and image read in will be somewhere between that size and 512x256.

It basically stops image reading from using up ALL your memory for very large JPEGs, until you can then resize it to size you really want.

Also the image read in will be a 'point sampled' image, not resized so quality will be bad. I recommend the size hint be at least twice the final size wanted.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply