Page 1 of 1

Speed up generation of multiple images

Posted: 2013-10-04T13:42:54-07:00
by bcbounders
Hi,

I'm new to ImageMagick and could use some help. I'm running IM through PHP and have to generate two lines of outlined text. The only way that I could get it to work and look the way I wanted was to do two convert commands to generate two versions of the same text... one with a white border, then one with the same size transparent border... so that I could overlay one over the other and get a white border around readable text.

Since I'm generating two lines of text, I needed 4 "convert" commands to create the two lines... and I just know this could be simplified in order to speed things up.

Here's the code I have right now:

Code: Select all

//Create Top Line with white stroke
$fontSize = $_REQUEST['fontSize'] * 6.927;
$top_line_filename = $output . "_top_line_" . urlencode($textLine1) . $fontName . ".png";
$command = "convert -background transparent -gravity center -stroke '#fffffe' -strokewidth 13 -fill '#120255' -font " . $base_path . "fonts/" . $fontName . '.ttf  -size 1270x300 -pointsize ' . $fontSize . ' label:"' . $textLine1 . '" -bordercolor none -border 2 -rotate 0 -distort Arc "45 0" ' . $top_line_filename;
$convert = $location . ' ' . $command;
exec($convert);

//Create top line with transparent stroke to overlay on previous image
$top_line_filename2 = $output . "_top_line2_" . urlencode($textLine1) . $fontName . ".png";
$command = "convert -background transparent -gravity center -stroke transparent -strokewidth 13 -fill '#120255' -font " . $base_path . "fonts/" . $fontName . '.ttf  -size 1270x300 -pointsize ' . $fontSize . ' label:"' . $textLine1 . '" -bordercolor none -border 2 -rotate 0 -distort Arc "45 0" ' . $top_line_filename2;
$convert = $location . ' ' . $command;
exec($convert);

//create bottom line with white stroke
$bottom_line_filename = $output . "_bottom_line_" . urlencode($textLine2) . $fontName . ".png";
$command = "convert -background transparent -gravity center -stroke '#fffffe' -strokewidth 13 -fill '#120255' -font " . $base_path . "fonts/" . $fontName . '.ttf  -size 1270x300 -pointsize ' . $fontSize . '  label:"' . $textLine2 . '" -bordercolor none -border 2 -rotate 0 -distort Arc "0 0" ' . $bottom_line_filename;
$convert = $location . ' ' . $command;
exec($convert);

//Create bottom line with transparent stroke to overlay on previous image
$bottom_line_filename2 = $output . "_bottom_line2_" . urlencode($textLine2) . $fontName . ".png";
$command = "convert -background transparent -gravity center -stroke transparent -strokewidth 13 -fill '#120255' -font " . $base_path . "fonts/" . $fontName . '.ttf  -size 1270x300 -pointsize ' . $fontSize . ' label:"' . $textLine2 . '" -bordercolor none -border 2 -rotate 0 -distort Arc "0 0" ' . $bottom_line_filename2;
$convert = $location . ' ' . $command;
Is there anything obvious here that would enable me to consolidate these four convert commands into one or two?

Thanks for your help!

- John

Re: Speed up generation of multiple images

Posted: 2013-10-04T13:56:47-07:00
by fmw42

Re: Speed up generation of multiple images

Posted: 2013-10-04T14:16:41-07:00
by bcbounders
@fmw42,

Thanks for the links. I've been checking these out for a little while (before today)... and just haven't been able to get them to work for me. Every time I try to combine the two commands for creating the top/bottom line of text, it fails and I get nothing.

If anyone can provide an example that is structured similarly to the way my code is working, that would be a HUGE help. I think I'm not ordering the commands correctly... and the need to concatenate all of the PHP variables together into the $command string being assembled for the $convert is making my eyes cross.

Appreciate the help!

- John

Re: Speed up generation of multiple images

Posted: 2013-10-06T11:58:29-07:00
by bcbounders
I'm still stuck on this... anyone out there able to give me a push? I'm not sure which of the items in the "$command" lines could be consolidated... where I need to "clone"... etc.

Help! :(

Re: Speed up generation of multiple images

Posted: 2013-10-06T12:46:06-07:00
by fmw42
can you rewrite your commands in simple direct notation with exact arguments and provide links to your input images.

it would make it easier for us to tell what you are doing and test ourselves.

Re: Speed up generation of multiple images

Posted: 2013-10-06T13:08:59-07:00
by Bonzo
Why do you have these in you code as far as I know -rotate 0 will have no effect and -distort Arc "0 0" will either throw an error or have no effect either.

An example of the output you want would be helpful and as fmw42 says supply some simple code. It always makes things easier if you can get the code working with direct inputs before you start using variables and values submitted from another page.

Re: Speed up generation of multiple images

Posted: 2013-10-06T14:02:15-07:00
by bcbounders
Thanks, guys... will do. I'll strip out the PHP variables and post the "clean" version of the commands along with sample output.

Appreciate the help!

- John

Re: Speed up generation of multiple images

Posted: 2013-10-06T15:42:07-07:00
by bcbounders
I think this should simplify things...

Here's the stripped down code for generating the top line of text, without the PHP variables being inserted:

Code: Select all

//Create Top Line with white stroke
$command = "convert -background transparent -gravity center -stroke '#fffffe' -strokewidth 13 -fill '#120255' -font /Users/bcbounders/Sites/babyloveshirts/fonts/Desyrel.ttf -size 1270x300 -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' output_topline.png";
exec($command);

//Create top line with transparent stroke to overlay on previous image
$command = "convert -background transparent -gravity center -stroke transparent -strokewidth 13 -fill '#120255' -font /Users/bcbounders/Sites/babyloveshirts/fonts/Desyrel.ttf -size 1270x300 -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' output_topline2.png";
exec($command);
The output from these two lines looks like this:
First Pass Top Line
Image

Second Pass Top Line
Image

Further code (GD Library) takes the two and merges them together later in the process, overlaying Line 2 on top of Line 1 so they look like this... the white stroke of the first showing through behind the transparent stroke on the second file:
Finished Text
Image

Does that make sense? Can those two lines be combined as one to speed processing?

Re: Speed up generation of multiple images

Posted: 2013-10-06T15:55:08-07:00
by fmw42
Using Arial as I do not have your font. You can replace with your font. Use parenthesis for each command with no output, then compose the second over the first.

This is unix syntax

convert \
\( -size 1270x300 -background transparent -gravity center -stroke "#fffffe" -strokewidth 13 \
-fill "#120255" -font Arial -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' \) \
\( -size 1270x300 -background transparent -gravity center -stroke transparent -strokewidth 13 \
-fill "#120255" -font Arial -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' \) \
-compose over -composite result.png

This is for windows:

convert ^
( -size 1270x300 -background transparent -gravity center -stroke "#fffffe" -strokewidth 13 ^
-fill "#120255" -font Arial -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' ) ^
( -size 1270x300 -background transparent -gravity center -stroke transparent -strokewidth 13 ^
-fill "#120255" -font Arial -pointsize 140 label:'Top Line' -bordercolor none -border 2 -rotate 0 -distort Arc '45 0' ) ^
-compose over -composite result.png

Re: Speed up generation of multiple images

Posted: 2013-10-06T15:59:45-07:00
by bcbounders
@fmw42,

SWEET! Thanks... I'll have to give that a try... then start peppering in the PHP variables to get it to work with my front-end. I want to do it right now... but I'm running out the door for dinner, so I'm gonna have to wait. BUMMER! But I'll report back.

Thanks so much!

- John

Re: Speed up generation of multiple images

Posted: 2013-10-07T15:41:17-07:00
by bcbounders
@fmw42,

You rock! That did the trick! I tested it first without the PHP variables being inserted and it worked, no problem. Now I've got my variables being inserted again... and all is right with the world.

Thanks, again, for taking the time to help out!

Really appreciate it.

- John