non square pixel aspect ratio in tiff files

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

non square pixel aspect ratio in tiff files

Post by Xandros »

Hi !

When trying to create thumbnails of some FAX generated tiff files, I stumbled on a strange behaviour ...

Using MagickWand API, what I do is :

Init wand
MagickReadFile('myfax.tif')
strip all profiles
resize
MagickImageWriteFile('thumb.png')

the result is a png file which image is distorted the same way as the original tiff pixel aspect ratio (this is the same distortion that happens if you open the tiff file in photoshop and manually disable the pixel aspect ratio correction and force display as square pixels.

however if the last step is

MagickGetImageBlob and then use external code to perform a binary write to file of the blob contents, the resulting png file is properly sized and the image is not distorted.

so the question is, what calls / options / properties do I have to make / set in order to be able to use the MagickImageWriteFile and get a non distorted image ?

FYI, using "convert myfax.tif -resize 200x200 thumb.png" via commandline also exhibits the same distorted result. if I force the resize geometry with !, i get the distorted result distorted a second time to fit the 200x200 size ...


Here is a link to get a small sample TIFF file to reproduce the issue :

http://uploadfile.org/download.php?id=1 ... Njil8upl3W


I also noticed that when thumbnailing PDF files, MagickImageWriteFile writes a good PNG file, while executing exactly the same code as above (the one leading to non distorted tiffs with MagickGetImageBlob) produces broken PNG files... Any thoughts on why this could happen please ?

Sample 'broken' png file for this case : http://uploadfile.org/download.php?id=R ... czJNohFAIL


Thanks !
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: non square pixel aspect ratio in tiff files

Post by magick »

You need to use the density / resolution. From the command line it looks like this:
  • convert 00079399627972.tif -density 100x150 image.png
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: non square pixel aspect ratio in tiff files

Post by Xandros »

ok so basically specify a different vertical & horizontal resolution, but when processing a folder full of tif files in a loop, how can I check if the current file loaded with readfile needs a pixel aspect ratio check or not ?

should this density be specified before readimage on the wand itself or after reading in the image, on the image ?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: non square pixel aspect ratio in tiff files

Post by magick »

The fax standard requires that the image width is 1728. You could assume a non-square aspect for images whose width is exactly 1728.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: non square pixel aspect ratio in tiff files

Post by Xandros »

mm ok thanks, I thought maybe there was some property or metadata field I could read ...

any ideas regarding the PDF related problem described above ?

thanks a lot !
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: non square pixel aspect ratio in tiff files

Post by magick »

00439811887517_thumb.png is not a PNG file, its a PDF.
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: non square pixel aspect ratio in tiff files

Post by Xandros »

ok found that there are tiff:XResolution / tiff:YResolution properties that can be checked for the fax issue.

oh ok it's a scaled down pdf right .... didnt figure. guess that's because I forgot to call MagickImageSetFormat before calling getblob right ? so in fact when calling getblob after converting from tiff, my png thumb file was in fact also containing a tiff image right ?

Thanks !

I'm asking so much questions because I'm rewriting an up to date and convenient MagickWand interface for Delphi :)
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: non square pixel aspect ratio in tiff files

Post by Xandros »

all ok for PDF, but

convert 00079399627972.tif -density 100x200 -resize 300x300 png24:image.png
convert 00079399627972.tif -density 200x100 -resize 300x300 png24:image.png
convert -density 100x200 00079399627972.tif -resize 300x300 png24:image.png
convert -density 200x100 00079399627972.tif -resize 300x300 png24:image.png
convert 00079399627972.tif -resize 300x300 png24:image.png

all produce the distorted version of the thumbnail (exactly same result for all five). (200x100 because the pixel aspect ratio is 2x1 in this file)

furthermore, instead of having a portrait oriented page the resize computes a landscape distorted pic 300 pixels wide and 199 high.... :(
Xandros
Posts: 28
Joined: 2009-10-02T09:19:49-07:00
Authentication code: 8675309

Re: non square pixel aspect ratio in tiff files

Post by Xandros »

oh well, the only thing that produces desired result is to retrieve the resolution of the image after reading it in, in case it is a tiff file. if the x and y resolution values are different, use MagickImageResample and set x and y to the same (max of the two) value. resizes and other following operations then yield expected file dimensions and looks. the only not nice thing about this is that it takes some time to perform the resampling.
Post Reply