PSD to JPG conversion takes extremely long time

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

PSD to JPG conversion takes extremely long time

Post by graemeNPS »

We use imagemagick to extract a jpg preview and jpg thumbnail from a wide variety of image file types, using a standard convert command to perform the initial extraction from (eg) a PSD file to a jpg preview, and then a resize on the jpg to get a thumbnail. We have a dll that statically links IM code based on the ImageMagick-6.5.5 release. We build an 8-bit version as it was faster for most of the files we use.

The essence of our usage is to call IM thus:
status=MagickCore::ConvertImageCommand(image_info,argc,argv,(char **) NULL,&exception);
where argv looks like this:
convert -auto-orient -size 8858x11457 \\validpath\somecustomerfilename.psd[0] -alpha Off -resize 512x512
-profile C:\Program Files\IPieces\CMYK.icc -profile C:\Program Files\IPieces\sRGB.icm
+profile "*" C:\DOCUME~1\someuser\LOCALS~1\Temp\220viewx.jpg


A client's CMYK PSD files are taking extremely long times to convert, and typically, the processing fails as certain components in our processing timeout after an hour. We do not have clearance from the client to upload the file, but I was hoping someone might have some insight into this issue. The problematic files are consistently large CMYK PSD files.

One of the PSD files in question is ~125MB; I used this version:
C:\Program Files\ImageMagick-6.5.4-Q8\imdisplay.exe
of imdisplay.exe to open the file by drag and drop on the UI. It wrote ~10GB of temporary files in the user temp directory, churned for 3 HOURS and finally opened the image.

Is there anything we can do to speed up the processing?

Thanks,
graeme
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

Append '[0]' to your PSD input image filename, e.g. image.psd[0]. That bypasses all the layers and just extracts the composited image.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by graemeNPS »

Thanks, but we already have image.psd[0] in our conversion string:
(from the original post) "convert -auto-orient -size 8858x11457 \\validpath\somecustomerfilename.psd[0]"

The ImageMagick libraries we statically link to are built in 8-bit mode from ImageMagick-6.5.5-8.zip sources.
Last edited by graemeNPS on 2010-01-11T10:06:53-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

If you image is large we suspect the image pixels are cached to disk which is 1000 times slower than caching to memory. See http://www.imagemagick.org/script/archi ... .php#cache.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by graemeNPS »

I updated imdisplay.exe and other IM components using this installer:
ImageMagick-6.5.8-10-Q8-windows-static.exe
With this installed, when I run this command in a cmd prompt window in the image directory:
convert bigimage.psd[0] bigimage.jpg
the process finished in about 2 minutes.
If I run this:
convert bigimage.psd bigimage.jpg
the process takes a very long time; I am not sure how long, I stopped it after 20 minutes, but I am guessing hours, as noted in my earlier post.
As noted earlier in this thread, we pass the layer index at the end of the filename (eg, filename[0].psd) into the convert code that we call programmatically, but it does not speed up the processing.
I wondered if the -ping option would help, but the result, though fast, is a blank (white) jpg of the correct size:
convert -ping bigimage.psd[0] bigimage.jpg

Since convert works at a tolerable speed, why does the code built from sources and using the same arguments not work at about the same speed?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

The ImageMagick Windows binaries are optimized and has OpenMP support enabled. This permits ImageMagick algorithms to run on multiple cores in parallel. The next release of ImageMagick will have some algorithms that can run on your GPU video processor for additional speed-ups.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by graemeNPS »

From our dll that implements imagemagick, I tried to call convert.exe directly:
int r = system((char*)cmd.c_str());
where cmd.c_str() is like:
[convert.exe "\\somevalidpath\bigimage.psd[0]" -resize 512x512 "\\somevalidtemppath\7944viewx.jpg"]
to see if we could call convert.exe directly and take advantage of the speedups, but the call returns instantly, with a return value of 1. The same command works on the command line. Any ideas on what might be preventing us from executing convert.exe programmatically? I tried renaming it to imconvert.exe, and that works on the command line but not from the program. convert renders the jpg in about 2 minutes.

I don't know if this is significant, but I noticed that when I run our version built on IM libraries and step into the code in psd.c, the file name is not adorned with the [0] tag when calling
static MagickBooleanType DecodeImage(Image *image,const long channel)
and most of the time is spent in there.
The [0] tag is lost in constitute.c in function
MagickExport Image *ReadImage(const ImageInfo *image_info,
ExceptionInfo *exception)
{
...
read_info=CloneImageInfo(image_info);
(void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent);
(void) SetImageInfo(read_info,MagickFalse,exception); <<< [0] tag is lost here...
(void) CopyMagickString(filename,read_info->filename,MaxTextExtent);
(void) CopyMagickString(magick,read_info->magick,MaxTextExtent);
....
}


When I open the problem psd files in IrfanView, it takes about ten seconds to render images from these files. What could Irfan be doing that makes it so fast?
We are not opening files for edit, we only want quick access to an accurate representation of the image to convert to a jpg for a preview and thumbnail. Is there anything we can add to the convert command to speed things up?

Thanks for your feedback,
graeme
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

Post a URL or send a PM to one of your images. We need to download it and convert it ourselves before we can offer any additional help.
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by graemeNPS »

There is a sample image Sample_PSD_CMYK.psd in a zip at our public ftp site:
ftp://publicforum:543publicforum123@nor ... D_CMYK.zip

The sample image behaves like our client's files; it takes IM a long time to process.
The zip also contains convertcommand.txt, which has some notes regarding our usage, including the convert command parameters we use programmatically, and the profile files we pass with the convert command.
We use imagemagick as 8-bit static libs linked into a dll designed to processs various image file formats.

Let me know if there is a problem with the URL.

thanks,
graeme
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

Can you check the link? We're getting 'Authorization failed.'
graemeNPS
Posts: 64
Joined: 2009-01-12T14:25:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by graemeNPS »

Try using the following credentials:

ftp.northplains.com
User name: publicforum
Password: 543publicforum123
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

The conversion completes for us in 1 minute on our Linux box with ImageMagick 6.5.9-0. However, if we first convert the PSD image file to MIFF, the conversion completes in 5 seconds. We'll need to investigate why it takes so much longer to read a PSD image. It will take a few days and we will post the results here.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

We have a patch that reduces the conversion time of your command to 12 seconds. Look for it in ImageMagick 6.5.9-1 Beta available by sometime tomorrow.
rylkov

Re: PSD to JPG conversion takes extremely long time

Post by rylkov »

I have downloaded & installed ImageMagick-6.5.9-5-Q16-windows-dll.exe to my laptop with Intel Celeron M CPU 430 @ 1.73GHz. I have noticed that IM converts my 100Mb PSDs in 40s while TIFFs in 5 s. I have pure Java image libraries as well. Same image files Sanselan converts in 30s, Imagero in 10s :shock:

Finally I have tried to convert above mentioned Sample_PSD_CMYK.psd. I waited minutes and finally have closed application. Although I used much simpler convert command: convert Sample_PSD_CMYK.psd -resize 512x512 Sample_PSD_CMYK.jpg.

Did you remove a patch from current version of IM?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSD to JPG conversion takes extremely long time

Post by magick »

We converted the Sample_PSD_CMYK.psd to JPEG in just 15 seconds with ImageMagick 6.5.9-6, the current release. Post a URL to your image and we'll report how long it takes to convert it. If it appears excessive, we'll investigate the source of the slow down.
Post Reply