Thanks everyone for the replies. I've managed to simplify this process greatly. now instead of 8 or whatever intermediate files i now have 2.. here's the code i simplified it into:

convert -size 320x320 DSCN9319.jpg \
       -thumbnail x320 -resize '320x<' \
       -gravity center -crop 320x320+0+0 +repage \
       -compress None cut_to_fit.png

convert -size 320x -background none -gravity center -pointsize 50 -fill white \
       caption:'TITLEE Blah BLAH' -shadow 70x8 -composite \
       caption:'TITLEE Blah BLAH' -shadow 50x4 -composite \
       caption:'TITLEE Blah BLAH' -composite \
       -compress None text.png

convert \
       cut_to_fit.png -composite \
       text.png -gravity south -composite \
       -bordercolor white -border 6 \
       -bordercolor grey60 -border 1 \
       -background none -rotate 18 \
       -background black \( +clone -shadow 60x4+4+4 \) +swap \
       -background  white -flatten \
       -thumbnail 160x160! \
       -quality 85 \
       out.jpg

This is the code written in bash for testing and ease of looking at it. I'm wondering if it can be simplified into just one command? The problem i'm running into is that the text needs to be layered ontop of eachother, if i try to layer it over the full image it won't line up properly with -gravity south, as the blurred text is larger than the non-blurred text. The non-blurred will end up lower in the image than the center of the blurred text if that makes any sense. Therefore i have the above solution making a seperate image where they can all be -gravity center and then taking that image and composing it over the larger image -gravity south.

Right now it takes ~ 2.4 seconds per image (depending on the size, most are my cameras default 'fine' quality). This is a big improvement over the old process which took 4 seconds for the same image. But i'm hoping it can be improved even more.

My script does cache images, it only generates them once (unless i clear the cache) But i will still like it to be faster if possible.

Thanks for all the help so far,
Jeff

Anthony Thyssen wrote:
Jeff Utter on  wrote...
| I currently have a PHP script that does some fancy image magick stuff
| for a web gallery. As it stands now i end up having to write like 6
| temporary files in the process of getting one output. It actually only
| takes about 2-3 seconds to run on a 1mb JPG, but i have a feeling that
| coudl be made much faster and the code much simpler. I store the temp
| files as uncompressed png's as it seems to be fast and it preserves any
| alpha channel stuff used in a few of the steps. A sample of what it
| looks like can be seen at: http://sadclown.net/gallery (images are
| cached, so hopefully it won't be too slow after they are viewed once)
|
| Here's basically what i'm doing (with most of the php chopped out)
|
| # Resize the original image to 2x the final size, so it is easier to
| work with.
| convert -size {$quadx}x{$quady} '$origPath' -thumbnail x{$doubley}
| -resize '{$doublex}x<' -gravity center -crop {$doublex}x{$doubley}+0+0
| +repage -compress None '$cut_to_fit' ;
|
| #This section is some voodoo, i can't remember exactly, to get a niec,
| smooth looking AA ish font with some depth to it
| convert -size {$doublex}x60 xc:none -gravity center -stroke black
| -strokewidth 4 -pointsize 14 -annotate 0 '$title' -channel RGBA -blur
| 0x3 -stroke none -fill white -pointsize 14 -annotate 0 '$title'
| '$cut_to_fit' +swap -gravity south -geometry +0+2  -composite -compress
| None '$label_fancy' ;
| convert -size {$doublex}x -background none -gravity center -pointsize 14
| -fill white caption:'$title' -compress None '$text1' ; ";
| convert $text1 -shadow 100x4 -compress None '$outline' ;
| composite -compose over -gravity center '$text1' '$outline' -compress
| None '$text2' ;
| convert '$text2' -shadow 70x8 -compress None '$shadow' ;
| composite -compose over -gravity center '$text2' '$shadow' -compress
| None '$text3' ;
| composite -compose over -gravity south '$text3' $cut_to_fit '$label_fancy' ;
|
| #Add a white border.
| convert '$label_fancy'  -bordercolor white  -border 6 -bordercolor
| grey60 -border 1 -background  none   -rotate $randomnumber -background
| black  \( +clone -shadow 60x4+4+4 \) +swap -background  white -flatten
| -compress None '$poloroid_single' ;
|
| #convert to final image
| convert '$poloroid_single'  -resize 250x250! -strip -depth 8 -colors 256
| -quality 85 '$newPath' ;
|
| If anyone can help me clean this up, it would be greatly appreciated.
|

I took a look at the above and most of it seems fine.  However
You can combine multiple convert commands together.

Each convert command at the end has a single image.  Rather than
save it to a file, you can just continue processing that image in the
same command.

The only exception to this is if the code needs to extract some extra
data from a generated image, before proceeding.  That does not appear to
be the case.

Even the 'composite' command can be turned into a convert operation.

All the lines givem appears to be a near direct extraction from IM examples.
So none of them appear too difficult.
  http://www.cit.gu.edu.au/~anthony/graphics/imagick6/

I would however start by re-adding the line by line formating
to make the processing steps easier to see...

The last two for example can be combine as..

  convert '$label_fancy' \
          -bordercolor white  -border 6 \
          -bordercolor grey60 -border 1 \
          -background  none   -rotate $randomnumber \
          -background  black  \( +clone -shadow 60x4+4+4 \) \
                    +swap -background  white -flatten \
          -resize 250x250! -strip -depth 8 -colors 256 \
                -quality 85 -compress None \
          '$newPath'

Removing the need for '$poloroid_single'  intermedite file.

Perhaps a seperate script can be used for the image processing, to
simplify the quoting that PHP is adding to the above.

  Anthony Thyssen ( System Programmer )    <[EMAIL PROTECTED]>
 -----------------------------------------------------------------------------
     Any problem in computer science can be solved
     with one more level of indirection.        --- Morven's Metatheorum
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/

_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to