Conversion from PSD to JPG produces too large file sizes?

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?".
Post Reply
tobiasbp

Conversion from PSD to JPG produces too large file sizes?

Post by tobiasbp »

Hello....

I have a CMYK PSD file created in Adobe Photoshop CS4 (test.psd).

Code: Select all

identify +ping test.psd 
  test.psd[0] PSD 2161x1276 2161x1276+0+0 8-bit DirectClass 5.467MiB 17.770u 0:17.500
  test.psd[1] PSD 2150x1276 2150x1276+11+0 8-bit DirectClass 5.467MiB 17.690u 0:17.439
I'm using ImageMagick on Ubuntu.

Code: Select all

convert -version
  Version: ImageMagick 6.5.7-8 2009-11-26 Q16 http://www.imagemagick.org
  Copyright: Copyright (C) 1999-2009 ImageMagick Studio LLC
  Features: OpenMP 


I would like to create a smaller version of the file and save it as a JPG.

Code: Select all

convert test.psd[0] -geometry 200x200 test.jpg
To my surprise, this results in a JPG files of size 3.5MB. The file can not be displayed by the standard image viewer in Ubuntu. Gimp and Firefox are both able to display the file.

Code: Select all

identify +ping test.jpg
  test.jpg JPEG 200x118 200x118+0+0 8-bit DirectClass 3.536MiB 0.030u 0:00.039
Setting the compression does not help.

Code: Select all

convert test.psd[0] -quality 50 -geometry 200x200 test.jpg
Any ideas on how to get a JPG of a more reasonable file size?

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

Re: Conversion from PSD to JPG produces too large file sizes

Post by fmw42 »

convert test.psd[0] -geometry 200x200 test.jpg
-geometry is a setting and not an operator. It is not the appropriate thing to change the size of the image. It is used in conjunction with composite operations to place (and sometimes resize) the image onto another.

In your case, use -resize or -thumbnail.

see

http://www.imagemagick.org/script/comma ... php#resize
http://www.imagemagick.org/script/comma ... #thumbnail
http://www.imagemagick.org/script/comma ... p#geometry
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Conversion from PSD to JPG produces too large file sizes

Post by Drarakel »

Apart from that:
- your PSD file is probably CMYK (which itself will make bigger files), so you might convert it to RGB first
- there's metadata in the PSD that you probably won't need anymore
- there's also an issue in ImageMagick that leads to the effect that the color profile from the PSD (if there is one) will be stored twice in the JPG (one color profile itself could have several MBs!)

So, a better, but simple command would be:
convert test.psd[0] -colorspace RGB -resize 200x200 -strip test.jpg
And then, of course, you can tweak the JPG settings with "-quality" and "-sampling-factor".

An even better command - with profiles:
convert test.psd[0] -profile sRGB.icm -resize 200x200 -strip test.jpg
For this to work, you must have color profiles and you have to assure that there's an embedded color profile in the PSD. If there's no embedded one, you have to specify the CMYK profile manually (before "-profile sRGB.icm").

See more about color profiles:
http://www.imagemagick.org/Usage/formats/#color_profile
Last edited by Drarakel on 2010-08-03T19:58:18-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Conversion from PSD to JPG produces too large file sizes

Post by fmw42 »

An even better command - with profiles:
convert test.psd[0] -profile sRGB.icm -resize 200x200 -strip test.jpg
For this to work, you must have color profiles and you have to assure that there's an embedded color profile in the PSD. If there's no embedded one, you have to specify the CMYK profile manually (before "-profile sRGB.cim").
Not knowing too much yet about profiles, what is the best method to find out if you have a profile that is usable and what kind it is?

I see you have .icm and .cim in your statement. Is this a typo? I have been using .icc profiles for my PSD. What are the differences? I guess they come from different types of profile files. Any good technical reading on (PSD) profiles (besides the IM examples page), something that explains the differences and such.

__________________

I have done a little reading and I guess icc is used on Mac and icm is used on PC, but they are really the same. PC apparently already uses .icc for something else. So on mac I guess you can rename them to either .icc or .icm.

I also see that identify -verbose lists icc (and presumably icm) profiles.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Conversion from PSD to JPG produces too large file sizes

Post by Drarakel »

fmw42 wrote:I see you have .icm and .cim in your statement. Is this a typo?
Yes. :)
fmw42 wrote:I have been using .icc profiles for my PSD. What are the differences?
The color profiles itself stay the same. There are many different profiles, of course - but there are no special profiles just for a different OS or for different file formats AFAIK. On Windows, the sRGB profile is sometimes still delivered with .ICM as ending (so is the 'sRGB.icm' that is contained in the IM binaries for Windows), but you shouldn't care about that. It's just a file ending.
In a current ImageMagick, a color profile is always reported as 'ICC' profile, I think. But I guess, it doesn't hurt to include 'ICM', too when one wants to.. strip the color profiles, for example (that would be '+profile "icc,icm"').
For specifications, you could try the ones from the ICC itself:
http://www.color.org/ICC_Minor_Revision_for_Web.pdf
http://www.color.org/ICC1v42_2006-05.pdf
But I never read these technical details myself - I only use the profiles. :D
fmw42 wrote:Not knowing too much yet about profiles, what is the best method to find out if you have a profile that is usable and what kind it is?
Just look at the "identify -verbose" output. If there's an ICC profile, you can use it. (Well, in some cases the color profile could be broken.. Or sometimes there's only an 'old' color profile embedded that doesn't fit anymore to the colorspace of the image. In areas where people don't know what color management is, that can happen often - sadly.)
Or just extract a potential color profile with "convert file ICC:file.icc". Or you could use Exiftool. Or an image viewer that is able to display the color profile names.
It would be nice if one could use a simple, automatic conversion with color profiles in IM that worked for every file (by e.g. specifying somewhere default color profiles for RGB and CMYK that would be used as source profile when there's no embedded source profile or a wrong embedded source profile). But currently, one has to do some checks oneself.
We had some approaches for an automated conversion in this thread lately:
viewtopic.php?f=1&t=16464
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Conversion from PSD to JPG produces too large file sizes

Post by fmw42 »

Thomas

Thanks for all the information. I had been reading some this afternoon and found much of what you had said in a number of web pages.

I tried to compare CMYK.icc to sRGB.icc versus USWebCoatedSWOP.icc to sRGB.icc and found the USWebCoatedSWOP.icc produces a noticeably brighter result, but still not as bright as the original image. Nevertheless, this does work better.

Thanks for all the tips and the link to the old post. It had some interesting scripting ideas for detecting profiles and using one or two profiles depending upon the situation. This is good background if I have to modify the script I am working on to handle transparent CMYK PSD files and overlaying them onto a checkerboard.

Fred

P.S. Apologies to the original poster as this is getting off his original topic.
tobiasbp

Re: Conversion from PSD to JPG produces too large file sizes

Post by tobiasbp »

Hello...

I have resolved my problem thanks to this thread. My problem was the embedded color profiles. Some observations below.

Code: Select all

convert test.psd[0] -resize 200x200 test.jpg
"Same" big file. My problem is apparently not due to my use of -geometry instead of -resize.

Code: Select all

convert test.psd[0] -strip -resize 200x200 test.jpg
convert test.psd[0] -strip -geometry 200x200 test.jpg
Both create the "same" small (15K) file.

Code: Select all

convert test.psd[0] -thumbnail 200x200 test.jpg
Produces a 1.7M file.

Code: Select all

convert test.psd[0] -strip -thumbnail 200x200 test.jpg
Produces a 15K file. This is what I'm doing now.

Thank you to all posters.
Drarakel
Posts: 547
Joined: 2010-04-07T12:36:59-07:00
Authentication code: 8675308

Re: Conversion from PSD to JPG produces too large file sizes

Post by Drarakel »

tobiasbp wrote:

Code: Select all

convert test.psd[0] -strip -thumbnail 200x200 test.jpg
Produces a 15K file. This is what I'm doing now.
Note that your file won't be very compatible (especially when stripping the color profile, too) - as you probably have a CMYK picture. So, it's usually better to add "-colorspace RGB" at least.
Post Reply