How to Change the Resolution of an Image

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?".
psuphish05

How to Change the Resolution of an Image

Post by psuphish05 »

Hello,

Thanks in advance for the help that is provided.

Currently, we converting .eps files to .jpg or .gif files. They need to be at a resolution of 72 dpi. Consequently, the resulting image is not 72 dpi but still at the original 300 dpi. This causes the image file size to be too large and the system we submit the images to throws an exception.

Here is the current command that I am using to convert the .eps files:

-resample 72 -units PixelsPerInch -size 8.02x8.02 A333.eps A333.jpg

or

-density72 -units PixelsPerInch -size 8.02x8.02 A333.eps A333.jpg

I have been confirming the resulting dpi in Paint.NET.

What am I doing wrong?

Again, thanks in advance and any and all help is greatly appreciated.

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

IM experts may correct me, as I don't use eps images.

But IM uses -size in pixels not inches or centimeters

also -size is for reading in jpg image not writing them out. you want -resize to resize the image to whatever output size you want unless you want to keep it at the same size as the input depending upon the density you set

try

convert -density 72 -units PixelsPerInch A333.eps A333.jpg


convert -density 72 -units PixelsPerInch A333.eps -resize widthxheight A333.jpg
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

Thanks for the advice! I tried your commands and a couple variations of it to no success.

The -resize reduced the image to almost next to nothing, but I figured out why - it was using pixels - so after adding in some quick math to convert the inches to pixels the image was the proper size. However, the resolution was still 300 dpi.

Here are the commands that I ran:

convert -density 72 -units PixelsPerInch A333.eps" -resize 577.44x577.44 A333.jpg

convert -resample 72 -units PixelsPerInch A333.eps" -resize 577.44x577.44 A333.jpg

I also tried specifying the -density and -resample to the width x height option (72x72) without any luck.

I am wondering if the source .eps file is preventing the conversion of the dpi to 72.

Any thoughts?

Thanks again for the help! Got me thinking more into this!

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

try

convert -density 300 -units PixelsPerInch A333.eps -resize 577x577 -density 72 -units PixelsPerInch A333.jpg

IM cannot resize to fractional pixels.


If all else fails, post a link to your eps file and perhaps someone can look at it to see if there is any issues.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to Change the Resolution of an Image

Post by anthony »

If you are wanting to keep the same real-world size of the image try using -resample instead...

convert -density 300 -units PixelsPerInch A333.eps -resample 72 A333.jpg

-resample does the resize (in pixel terms) based on the change in resolution, so as to preserve the images 'real world' size.
httrp://www.imagemagick.org/Usage/resize/#resample

Otherwise you would need to do the calculations for the number of pixels yourself.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

Thanks again for everyone's help. I figured out the solution to our issue using the mogrify command rather than convert.

However, this led to an additional issue: mogrify requires the target file to be present in order to run, whereas convert doesn't. My question is, is there a way to combine the convert and mogrify actions together?

Thanks again!

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

convert should be able to do what you want, but you do need to give it an output name.

what were you doing with mogrify -- that is what is your command?
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

Correct, the output name is required for both convert and mogrify. However, mogrify requires that the output file be physically present.

I could not get convert to produce the desired output results - even when implementing the commands above. Reading into IM, I saw that mogrify handles resize, etc. manipulations.

My issue is now, we have a .eps but no physical output file for mogrify. It throws the error:

mogrify: unable to open image `\A0003.jpg': No such file or directory @ blob.c/OpenBlob/2431.

When I attempt to run it without the output file physically there.

That is why I am wondering if it is possible to combine the convert (to generate the output file for mogrify) and mogrify (to manipulate the image as we need) commands together.

Here is my mogrify command:

mogrify "A0003.eps" -resample 72 -resize 288x288 -units PixelsPerInch "A0003.jpg"

Thanks again!

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

I don't understand what you mean by 'having a physical file present'

IM whether convert or mogrify will make a file to disk if you supply an output file. If you don't supply the output file, you will get an error! The only way around that is to use null: for the output. But I don't see the point of that for what you are trying to do.

I need further clarification of what your objective is?

I am confused.

Why would you want to process an image and not save the result? The only way to save the result is to supply an output name.

Mogrify allows you to get the output name from the input name as the input can be *. But you cannot do this with convert. Mogrify allows such as it processes multiple image whereas convert handles only one image at a time.

The only way to do this with convert is to write a script and have the script extract the input name and use that as part of the output name. Then you can loop over multiple images and process them all the same way and get output names that follow the input naming scheme
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

Sorry, didn't catch your whole post before I replied. So you're saying there is no way to combine the commands together? I'll just need to run two separate commands, one for convert; and one for mogrify.

No problem! Thanks again!

********************************************************************************************

I mean that the file is physically on the disk. Our conversion process begins with just an .eps file. There is no .jpg or .gif file. That is what we are creating and converting from the .eps.

When I run convert, it will create the .jpg/.gif file. If I solely run mogrify on the .eps it errors saying that the result file I specified does not exist (mogrify: unable to open image `\A0003.jpg': No such file or directory @ blob.c/OpenBlob/2431.).

I need to:

1.) Convert the .eps file to .jpg/.gif.
2.) Manipulate the result file for resampling, resizing, etc using mogrify.

I was wondering if I could run convert and mogrify in the same command rather than running two separate commands in my application.

Hope this clarifies and thanks again!

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

convert and mogrify are two totally different and unmixable commands.

To run mogrify, you cannot specify an input or an output file as it takes the filename from the images in the folder it is processing. Mogrify processes EVERY file in the current folder. The syntax is

mogrify -path path_to_newimage_folder options -format desired_format wildcard

for example

cd folder
mogrify -path /User/fred/folder2 options -format jpg *.png

will process every png file in folder1 and process them using the options specified and make an image in jpg format for each and place it in folder2. NOTE folder 2 must exist already.

So whatever are the names of the png files in folder1, every one will be processed into jpg files with the same name. You have no control over the output name. It will be the same as every file in folder1. All you can do is change the file type.

Convert processes one image and allows you to specify the output name. In fact, if not provided, it will give an error unless you use null:, which then produces and image and throws it away.

see http://www.imagemagick.org/Usage/basics/#mogrify

If you want to specify a unique input and output then you have to use convert.
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

Thanks for the clarification and the additional info on mogrify. Yes, this could turn out to be bad for business since it runs against a whole directory of files.

But, unfortunately, this brings me back to where I start: convert is not giving the desired output.

Thanks again for all your help, and I'm going to keep playing with the convert argument to get what I need!

- Jesse
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to Change the Resolution of an Image

Post by fmw42 »

if the command options work for mogrify then they should also work the same for convert. So you are doing something that is not quite what you think you are doing or using the wrong commands.
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

With a little massaging of the command, I was able to get the resolution to maintain from the source to the output. Just a little issue with the actual resizing of the image. It seems that the width is not maintaining. I'm thinking it has to do with the actual resolution of the source file. I'm waiting on word from our art department on what the resolution of the source is.

Thanks again for all your help and patience!

- Jesse
psuphish05

Re: How to Change the Resolution of an Image

Post by psuphish05 »

I guess I do have one more question in regards to our conversion:

Can I have multiple crop actions in a single command?

We need to be able to trim up a combination of either the top, right, bottom, or left. I have the geometry defined for each side, but was wondering if there was a way to specify multiple crops.

Thanks again!

- Jesse
Post Reply