Page 1 of 1

Problems with resampling to change resolution

Posted: 2008-04-16T11:41:27-07:00
by Slowfamily
Hello,

I am trying to reduce the resolution of images to 72x72 using convert -resample 72x72
when I do this the image size does get reduced, but when using identify on the image it says the resolution is still something else. I've even tried running -density 72x72 to specify the new density, but that doesn't seem to work either.

Any ideas what might be going on here?

Thanks in Advance!

Re: Problems with resampling to change resolution

Posted: 2008-04-16T13:54:28-07:00
by fmw42
Resolution and Density are two different things.

convert image -resize 72x72! result

will make a new image whose dimensions are 72x72 pixels.

Density has to do with how many dots/in when printing. A nominal image will have a density of 72 dpi unless you specify something else with -density ( or if had something else to start with).

Re: Problems with resampling to change resolution

Posted: 2008-04-16T15:45:55-07:00
by Slowfamily
Thanks for replying, fmw42.

My very limited understanding is that -resample changes the dpi. This means that with a lower dpi, the image quality may not be as good, but will be smaller since there are fewer dots that need to be recorded. The image size should stay the same, however. I do not want the images to be a different dimension, only smaller in diskspace.

-density doesn't necessarily change the resolution of an image, but rather tags the image as being of a certain resolution. This would be used to tell a printer how many dpi to print, or to use if you have an image format that doesn't contain resolution info to specify what the assumed resolution should be.

My problem is that after resampling a bunch of images to use for the web, some of them resample, say that their resolution is now 72x72, and they appear the same size on a website. Others, however, appear much smaller online now, which I'm guessing is because the resolution has been altered, but the header in the jpg says that the image is of a much greater resolution. I will admit this is just my guess, however.

Please correct me if I'm wrong about any of this.

Re: Problems with resampling to change resolution

Posted: 2008-04-16T16:25:33-07:00
by fmw42
Sorry, I am not all that familiar with -resample. Hopefully someone else will be able shed more light on this subject for you. I apologize. I misread your first message and thought you were using -resize and not -resample.

Re: Problems with resampling to change resolution

Posted: 2008-04-18T12:01:35-07:00
by Slowfamily
So I figured out that part of the problem involved photoshop header information. I had read mention of that but didn't realize it affected any file touched by photoshop. I stripped out the header information, but still I have the same problem. The images get resampled but appear smaller in size, which was what I thought resample was exactly supposed to keep from happening! Help!

Re: Problems with resampling to change resolution

Posted: 2008-04-19T14:02:13-07:00
by fmw42
see

http://www.imagemagick.org/Usage/resize/#resample

I think -resample (as it is built from -resize) will change the number of pixels in the image as well as the density to work with a piece of hardware that is keyed to a specific resolution. Thus the final resolution of the image in combination with the number of pixels will produce the resolution (density) that in combination matches the density needed for that hardware.

I hope this page helps. I am no expert on -resample, but found this page and wanted to point you to it. Perhaps someone else who is more experienced with -resample can comment.

Re: Problems with resampling to change resolution

Posted: 2008-04-23T16:43:15-07:00
by Slowfamily
So I finally got it to do what I wanted to: reduce the filesize of the images, while retaining the same dimensions. In order to do this I had to run a command like this:

convert -strip -density 72 -resample 72x72 oldfile.jpg newfile.jpg

It seems kind of strange that by setting the density to 72, and then resampling it to 72, it would perform this. I would think that since I declare the density to be 72, and then try to resample it to 72, that nothing would happen.

Could anyone explain this to me?

Re: Problems with resampling to change resolution

Posted: 2008-04-23T19:45:24-07:00
by fmw42
I found the following information at

http://www.imagemagick.org/Usage/resize/#resample

"Note that only a small number of image file formats (such as JPEG, PNG, and TIFF) are capable of storing the image resolution or density with the image data.

For formats which do not support an image resolution, or which are multi-resolution (vector based) image formats, the original resolution of the image must be specified via the "-density" attribute (see Density Image Meta-data) before being read in. If no density attribute has been set IM will assume it has a default density of 72dpi. Setting the density AFTER reading such an image will only effect its output resolution, and not effect its final size in terms of pixels."


Also I believe that your convert syntax may be incorrect. Usually the input image comes right after convert, with the exception of the some parameters that need to be set beforehand. So I would expect you should have either

convert -strip -density 72 oldfile.jpg -resample 72x72 newfile.jpg

or possibly

convert oldfile.jpg -strip -density 72 -resample 72x72 newfile.jpg

Re: Problems with resampling to change resolution

Posted: 2008-05-20T20:11:36-07:00
by anthony
Slowfamily wrote:Could anyone explain this to me?
The problems are with the order of arguments.

-density override the density set in images read in AFTER that setting, as such when you read your image it thinks it is 72 dpi already, so -resample doesn't do anything. Try...

Code: Select all

   convert  oldfile.jpg -strip -resample 72x72 newfile.jpg
and it should then do what you expect!

Remember image reading is an operator, and unless in the special legacy mode (which may fail, such as in this case) Im will perform all operations in the order given.

If you know the resolution of the image when readin in, you can do...

Code: Select all

convert -density 300 oldfile.jpg -strip -resample 72x72 newfile.jpg