Density does not work on some JPG images
Density does not work on some JPG images
I'm using Ubuntu 16.04 and ImageMagick 6.8.9-9.
Here's an example of -density working correctly:
https://upload.wikimedia.org/wikipedia/ ... d_test.jpg
convert Image_upload_test.jpg -density 300 Image_upload_test2.jpg
When you check Image_upload_test2.jpg, the DPI is correctly set from 120 to 300
However, it doesn't work on this image:
http://render2.fotofuze.com/8680100E-3E ... 6AABD7.jpg
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg -density 300 8680100E-3E64-11E6-BF87-F5A2E46AABD7_2.jpg
The DPI doesn't change. Using Gimp to change the DPI and exporting the image will make ImageMagick's -density work again.
On another computer of mine that runs an older version of ImageMagick (6.7.7-10), this problem doesn't exist.
Here's an example of -density working correctly:
https://upload.wikimedia.org/wikipedia/ ... d_test.jpg
convert Image_upload_test.jpg -density 300 Image_upload_test2.jpg
When you check Image_upload_test2.jpg, the DPI is correctly set from 120 to 300
However, it doesn't work on this image:
http://render2.fotofuze.com/8680100E-3E ... 6AABD7.jpg
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg -density 300 8680100E-3E64-11E6-BF87-F5A2E46AABD7_2.jpg
The DPI doesn't change. Using Gimp to change the DPI and exporting the image will make ImageMagick's -density work again.
On another computer of mine that runs an older version of ImageMagick (6.7.7-10), this problem doesn't exist.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Density does not work on some JPG images
Checking that file using "ImageMagick 6.9.3-9 Q16 x64" on Windows 7 64 using this command...david_o wrote:However, it doesn't work on this image:
http://render2.fotofuze.com/8680100E-3E ... 6AABD7.jpg
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg -density 300 8680100E-3E64-11E6-BF87-F5A2E46AABD7_2.jpg
Code: Select all
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg -verbose info:
Code: Select all
Image: 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1567x1567+0+0
Resolution: 300x300
...
...
Re: Density does not work on some JPG images
Other programs can't seem to identify the resolution as 300 (such as Gimp and programs trying to print the photo). Any idea why?
Re: Density does not work on some JPG images
For example, if you open the file in Gimp, click Image -> Scale Image you'll see that the DPI is not 300. If you right click the file on Windows and select Properties -> Details you'll see the horizontal and vertical resolution is not 300. I've had people tell me that Photoshop can't detect that the resolution is 300 either.
I'm not suggesting that ImageMagick isn't writing the Exif data in such a way that it can't read it properly. I'm suggesting that ImageMagick is writing the Exif data in such a way that other programs can't read it properly. ImageMagick used to write things correctly, but it seems a bug has been introduced at some point.
I just installed 6.9.5-1 and the bug still exists.
I'm not suggesting that ImageMagick isn't writing the Exif data in such a way that it can't read it properly. I'm suggesting that ImageMagick is writing the Exif data in such a way that other programs can't read it properly. ImageMagick used to write things correctly, but it seems a bug has been introduced at some point.
I just installed 6.9.5-1 and the bug still exists.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Density does not work on some JPG images
Try adding "-units PixelsPerInch" to your command line ahead of setting the "-density".david_o wrote:I'm not suggesting that ImageMagick isn't writing the Exif data in such a way that it can't read it properly. I'm suggesting that ImageMagick is writing the Exif data in such a way that other programs can't read it properly.
Code: Select all
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg -units PixelsPerInch -density 300 8680100E-3E64-11E6-BF87-F5A2E46AABD7_2.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Density does not work on some JPG images
GeeMack is correct. Your input image has no defined units. So other programs do not know how to interpret the density. Is it pixels per inch or pixels per centimeter? If your units are undefined, it causes problems.
identify -verbose 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg
Image: 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1567x1567+0+0
Resolution: 300x300
Print size: 5.22333x5.22333
Units: Undefined
...
Providing the units along with the density should work properly.
Imagemgaick is likely assuming units of pixelsperinch to convert from resolution to print size. But other programs may not work correctly if the units are not specified.
identify -verbose 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg
Image: 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Mime type: image/jpeg
Class: DirectClass
Geometry: 1567x1567+0+0
Resolution: 300x300
Print size: 5.22333x5.22333
Units: Undefined
...
Providing the units along with the density should work properly.
Imagemgaick is likely assuming units of pixelsperinch to convert from resolution to print size. But other programs may not work correctly if the units are not specified.
Re: Density does not work on some JPG images
I believe you are correct. Specifying the units makes it work.
It looks like the commit that broke things was made back on Sept 25, 2013: http://git.imagemagick.org/repos/ImageM ... a6e0801947
You can see that the code defaults to density_unit to 1 (pixels per inch) at line 2129. But when the x_resolution and y_resolution are both not 0, the density_unit changes to 0 (undefined).
This is inconsistent with the ImageMagick docs which explicitly states "The default unit of measure is in dots per inch (DPI). The -units option may be used to select dots per centimeter instead." ( http://www.imagemagick.org/script/comma ... hp#density )
I will add the -units PixelsPerInch for now, but this really should be fixed as it's a bug. If there is a good reason why it is set to 0, then the docs really should be changed.
It looks like the commit that broke things was made back on Sept 25, 2013: http://git.imagemagick.org/repos/ImageM ... a6e0801947
You can see that the code defaults to density_unit to 1 (pixels per inch) at line 2129. But when the x_resolution and y_resolution are both not 0, the density_unit changes to 0 (undefined).
This is inconsistent with the ImageMagick docs which explicitly states "The default unit of measure is in dots per inch (DPI). The -units option may be used to select dots per centimeter instead." ( http://www.imagemagick.org/script/comma ... hp#density )
I will add the -units PixelsPerInch for now, but this really should be fixed as it's a bug. If there is a good reason why it is set to 0, then the docs really should be changed.
Re: Density does not work on some JPG images
The current release of ImageMagick does not set jpeg_info.density_unit to 0. Perhaps that was a transient bug. Here is the current state of JPEG density settings:
Code: Select all
if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
{
/*
Set image resolution.
*/
jpeg_info.write_JFIF_header=TRUE;
jpeg_info.X_density=(UINT16) image->resolution.x;
jpeg_info.Y_density=(UINT16) image->resolution.y;
/*
Set image resolution units.
*/
if (image->units == PixelsPerInchResolution)
jpeg_info.density_unit=(UINT8) 1;
if (image->units == PixelsPerCentimeterResolution)
jpeg_info.density_unit=(UINT8) 2;
}
Re: Density does not work on some JPG images
Yes, currently units is set to 0 at line 1109, it gets the information from the Exif data, and sets the units to whatever the Exif data is currently set to.
Then later it sets the Exif data as was previoiusly set. (I'm assuming image->units is defaulted to 0, otherwise that would be a bug)
This is all perfectly fine, except that the documentation states that unless specified that density_unit should always be 1 (PixelsPerInch). If this is no longer how ImageMagick wants to function, then the documentation should be updated with an errata stating that people using ImageMagick versions earlier than 7.0.2-3 will have PixelsPerInch as the default unless specified with the -units option.
This change in how ImageMagick functions is undocumented and may give developers upgrading from Ubuntu 14.04 to 16.04 headaches when they find out things have been silently failing and there's no official documentation as to why.
Code: Select all
units=0;
if ((jpeg_info.saw_JFIF_marker != 0) && (jpeg_info.X_density != 1) &&
(jpeg_info.Y_density != 1))
{
image->resolution.x=(double) jpeg_info.X_density;
image->resolution.y=(double) jpeg_info.Y_density;
units=(size_t) jpeg_info.density_unit;
}
if (units == 1)
image->units=PixelsPerInchResolution;
if (units == 2)
image->units=PixelsPerCentimeterResolution;
Code: Select all
if ((image->resolution.x != 0.0) && (image->resolution.y != 0.0))
{
/*
Set image resolution.
*/
jpeg_info.write_JFIF_header=TRUE;
jpeg_info.X_density=(UINT16) image->resolution.x;
jpeg_info.Y_density=(UINT16) image->resolution.y;
/*
Set image resolution units.
*/
if (image->units == PixelsPerInchResolution)
jpeg_info.density_unit=(UINT8) 1;
if (image->units == PixelsPerCentimeterResolution)
jpeg_info.density_unit=(UINT8) 2;
}
This change in how ImageMagick functions is undocumented and may give developers upgrading from Ubuntu 14.04 to 16.04 headaches when they find out things have been silently failing and there's no official documentation as to why.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Density does not work on some JPG images
I believe a decision was made not too long ago. That was not to force an unknown density to units of dots per inch, but to leave it unspecified. I believe someone complained that units were being set wrongly for some images under those conditions. I could be wrong and defer to the IM developers.
However, I would agree that the whatever the situation, it should be properly documented.
see the changelog
2015-05-03 6.9.1-3 Dirk Lemstra <dirk@lem.....org>
...
Jpeg images no longer have pixels per inch as a default value for density units when the density is not set (reference viewtopic.php?f=3&t=27589).
However, I would agree that the whatever the situation, it should be properly documented.
see the changelog
2015-05-03 6.9.1-3 Dirk Lemstra <dirk@lem.....org>
...
Jpeg images no longer have pixels per inch as a default value for density units when the density is not set (reference viewtopic.php?f=3&t=27589).
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Density does not work on some JPG images
I suggest the documentation at http://www.imagemagick.org/script/comma ... hp#density has the following removed:
Those sentences are misleading. Replace them by:The default unit of measure is in dots per inch (DPI). The -units option may be used to select dots per centimeter instead.
I don't think the documentation needs to define the behaviour for the four cases when there is no "-units" setting in the command. (Four cases: the input image has one of the three -units settings, or the input comes from somewhere like xc:). But it could, if someone wants to define that behaviour.The -density setting should generally be used with the -units setting.
snibgo's IM pages: im.snibgo.com
Re: Density does not work on some JPG images
The only other oddity I see is..
This gives back:
This is an annoying discrepency. The TGA should return PixelsPerInch. Alternatively, converting a TGA to a JPG should keep the units as Undefined.
Code: Select all
convert 8680100E-3E64-11E6-BF87-F5A2E46AABD7.jpg 8.tga
convert 8.tga -verbose info:
However, if you then convert the TGA back to a JPG:Geometry: 1567x1567+0+0
Resolution: 72x72
Print size: 21.7639x21.7639
Units: Undefined
Code: Select all
convert 8.tga 8.jpg
convert 8.jpg -verbose info:
When using a format that doesn't support EXIF, the units change from Undefined to PixelsPerInch when converting it to JPG. It looks like PixelsPerInch IS the default, but only when converting from a format that doesn't support a units equivalent field.Geometry: 1567x1567+0+0
Resolution: 72x72
Print size: 21.7639x21.7639
Units: PixelsPerInch
This is an annoying discrepency. The TGA should return PixelsPerInch. Alternatively, converting a TGA to a JPG should keep the units as Undefined.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Density does not work on some JPG images
Here are some other oddities:
Code: Select all
f:\web\im>%IM%convert xc: x.png & %IM%identify -verbose x.png |grep Units
Units: Undefined
f:\web\im>%IM%convert xc: x.jpg & %IM%identify -verbose x.jpg |grep Units
Units: Undefined
f:\web\im>%IM%convert xc: x.tga & %IM%identify -verbose x.tga |grep Units
Units: Undefined
f:\web\im>%IM%convert xc: x.tiff & %IM%identify -verbose x.tiff |grep Units
Units: PixelsPerInch
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Density does not work on some JPG images
Perhaps it has to do with which formats support "undefined" for units.