Page 1 of 1

Resampling - Newbie

Posted: 2014-03-07T14:58:13-07:00
by Andy79
Hello everybody!

Got probably a very basic question regarding Resampling.

I have to Resample our entire Item Picture Collection for ERP Reports.
They are all in JPG Format in different Resolutions (DPI) and Sizes (Pixel).

Destination is to resample the Image so it matches 4.5 inches in width, changing
the dpi. I am not looking for filesize reduction. The destinationfile may
already exist so it should automatically override it.

How would I do that?

Thanks for the help!!

Re: Resampling - Newbie

Posted: 2014-03-07T15:12:08-07:00
by fmw42
What version of IM are you using and what platform.

You will need to get the image width and then compute what density you need to make it 4.5 inches.

Please clarify the above and we can help you. The command syntax differs on Unix(Linux/Mac) and Windows.

In Unix, this would be something like

density=`convert yourimage -format "%[fx:w/4.5]" info:`
convert yourimage -density $density -units pixelsperinch resultimage

Re: Resampling - Newbie

Posted: 2014-03-07T15:26:22-07:00
by snibgo
Destination is to resample the Image so it matches 4.5 inches in width, changing the dpi.
Do you want to change the number of pixels (keeping the physical size constant), or change the pixels per inch (keeping the number of pixels constant), or what?

To change the number of pixels, keeping the physical size constant:

Code: Select all

convert in.jpg -resample 250x250 out.jpg
To change just the DPI, I suggest you use exiftool with a command like:

Code: Select all

exiftool -JFIF:XResolution=250 -JFIF:YResolution=250 x.jpg

Re: Resampling - Newbie

Posted: 2014-03-07T16:59:16-07:00
by fmw42
User snibgo has a point. It is best not to use IM to process from jpg to jpg just to change the density. IM will decompress and recompress and therefore your quality will go down.

Re: Resampling - Newbie

Posted: 2014-03-12T10:18:19-07:00
by Andy79
The Platform is Windows 2008 R2 Server.

I use the Images in an ERP Report (Crystal Reports 2008). The Pixels of the Image is acutally not that relevant. Crystal Reports
displays the Image based on the Image "Print Size" so as Long as the Pixels by DPI match to 4.5 Inch I'm all set.

The tricky part is that the Images are uploaded into the ERP by users without regard for "printability". Therefor I also
have among great Images some with just 200 x 200 Pixels at 72 dpi and even less.

Regardless I have to get them to Print at 4.5 Inches - even if they are grany and not much to look at.


Sorry for the delayed repost. I had an unsheduled Business trip and was unable to work on the Project.

Re: Resampling - Newbie

Posted: 2014-03-12T10:24:39-07:00
by fmw42
compute the density = (image width in pixels)/4.5, then use EXIFTOOL as user snibgo suggested to change the density in the file so that there is no loss in quality

I am not a Windows user, so do not know the Windows syntax to put the computation in a variable and apply it to your image. You will also have to write a bat file to loop over each image or drag and drop them onto the bat file.

Perhaps one of the Windows users can be more informative.

Re: Resampling - Newbie

Posted: 2014-03-12T10:27:09-07:00
by Andy79
How would I do that? The Image Width is not known to me. Althought ist contained in the file I have to modify...

snibgo is changing the Pixels as far as i understand the commandline he posted.

Re: Resampling - Newbie

Posted: 2014-03-12T10:28:54-07:00
by fmw42
Andy79 wrote:How would I do that? The Image Width is not known to me. Althought ist contained in the file I have to modify...
In unix syntax,

density=`convert image -format "%[fx:w/4.5]" info:`

where w is automatically retrieved from the IM image information

But the syntax is different for Windows. So one of the Windows users will need to help further.

For new users, these reference may be of help
http://www.imagemagick.org/Usage/windows/
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
http://www.imagemagick.org/script/comma ... ptions.php
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/transform/#fx_escapes
http://www.imagemagick.org/script/escape.php

Re: Resampling - Newbie

Posted: 2014-03-12T10:49:21-07:00
by snibgo
In theory, the best approach should be to change metadata with exiftool, such that DPI=pixels/4.5. You need to decide what to do with non-square images. Perhaps the longest dimension should be 4.5 inches. Then Crystal Reports will do whatever it does.

Windows BAT syntax, changing DPI so the maximum dimension is 4.5 inches:

Code: Select all

for /F "usebackq" %%L in (`identify -format "DPI=%%[fx:max(w,h)/4.5]" %1`) do set %%L

exiftool -JFIF:XResolution=%DPI% -JFIF:YResolution=%DPI% %1
However, Crystal Reports might resize, increasing the number of pixels, and IM might do a better job of this. For example, a printer might work at 600dpi, so a 200x200 pixel image looks pretty silly. You might test this.