Page 1 of 1

Looking For Solution Input Please

Posted: 2008-09-03T13:49:25-07:00
by vendetta
Hey All,

I'm a fairly experienced php programmer but don't do a lot of command line or image work, I'm a complete newbie to IM, just started fiddling with yesterday.

I've spent many hours reading through the documentation and playing with some examples, without much success.

If possible I'd like to describe what I need to accomplish and see if I can get some feedback on what the best solution for this would be, from all the examples I've seen it seems like IM would be the correct solution and should be able to handle what I need with no trouble, but darned if I can get it to work yet, so I thought I'd come here and ask the pros!

I'm producing a monthly program whereby my members will be able to resell products we produce under their own name. With each product we're producing very nice graphic book covers and product boxes, leaving the author area blank.

What I need to do is be able to dynamically create and image of the member's name, apply some perspective distortion to it so that it matches the flow of the text on the existing box, then combine the two images so that the cover or box looks authentic and represents the product as authored by the member who's page the image is sitting on.

I started by attempting this in GD2, which worked ok except there doesn't seem to be a way to apply perspective to the text so that it will match the perspective of the cover. So I started looking at IM and it's like the right solution, I just can't get it to come together.

I'd be happy to pay someone for this, or do it myself if someone can provide me some guidance.

Thanks so much in advance for any assistance.

Tai

Re: Looking For Solution Input Please

Posted: 2008-09-03T14:04:50-07:00
by Bonzo
Here is a box created from scratch: http://www.rubblewebs.co.uk/imagemagick ... fo=box.png

NOTE: The distort settings were changed so you need to post your IM version.

You could either do your box as above or just create the text in a rectangular area and distort that and as you say paste it onto the box.

Some other IM and php examples on my site.

Re: Looking For Solution Input Please

Posted: 2008-09-03T14:14:05-07:00
by vendetta
Ok thanks I'll look at that again, I can't utilize the entire box, but perhaps I could utilize some of it.

My version is 6.2.8.0-4.el5_1.1.i386

Thanks.

T

Re: Looking For Solution Input Please

Posted: 2008-09-03T14:20:01-07:00
by Bonzo
I have to go now but the example I posted will not work for your IM version and I do not even know if you can use distort on that version.

Try running this and see what you get:

Code: Select all

<?php
echo "<pre>";
system ("convert -list distort");
echo "</pre>";
?> 

Re: Looking For Solution Input Please

Posted: 2008-09-03T14:27:41-07:00
by vendetta
Ah, maybe that's the problem.

Yeah it just produces a blank page.

Let me see if I can install a new version through yum.

I'll report back if I can get your code example to run on my server.

Thanks again.

Tai

Re: Looking For Solution Input Please

Posted: 2008-09-03T15:53:08-07:00
by fmw42
IM can do a lot to convert text into images.

See:
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/fonts/
http://www.imagemagick.org/Usage/annotating/

I even have a bash shell script using command line IM to create a bunch of effects. See texteffects at:
http://www.fmwconcepts.com/imagemagick/index.html

Perspective distortion can be found at:
http://www.imagemagick.org/Usage/distorts/#perspective

I also have a script that will do 3D rotation in perspective of an image. see either rotate3D or 3Drotate at:
http://www.fmwconcepts.com/imagemagick/index.html

With regard to creating a 3D box in perspective: see Anthony's examples at:
http://www.imagemagick.org/Usage/distorts/#box3d

You will have to use PHP exec or one of the PHP APIs to convert the command line example into one for use with PHP.
See the IM API forums at:
viewforum.php?f=15

Re: Looking For Solution Input Please

Posted: 2008-09-03T17:05:34-07:00
by vendetta
Ok,

Upgraded to 6.4.3

When running the code to create a box from your example I get the following:

The image http://mydomain.com/file.php cannot be displayed because it contains errors.

Here is the code for reference copied from the Rubblewebs page you referenced me to:

Code: Select all

header('Content-Type: image/png');
// Generate the Spine Image
$cmd = " -size 200x40 xc:lightblue ".
"-pointsize 20 -gravity north -annotate +5+0 \"Rubblewebs\" ".
" -pointsize 10 -gravity south -annotate +0+0 \"Website design\" ".
" -stroke blue -strokewidth 2 -draw \"line 30,0 30,40\" -rotate -90 ";
  
system ("convert $cmd spine.png ");

// Generate the front cover - text and image
$cmd =" -size 150x200 xc:lightblue ".
"  -fill black -pointsize 20 -gravity north -annotate +0+5 \"Rubblewebs\" ".
"  -fill blue -pointsize 15 -gravity northeast -annotate +5+28 \"Box Set\" ".
" -fill black -pointsize 15 -gravity south -annotate +0+5 \"Website design\" ".
" -stroke blue -strokewidth 2 -draw \"line 0,169 150,169\" ".
" ( http://www.rubblewebs.co.uk./images/logo.gif -resize 100x100 ) ".
" -gravity center -compose multiply -composite ";
  
system ("convert $cmd front.png ");

// Distort both images and merge together.
$cmd =" spine.png -virtual-pixel transparent ".
" +distort Perspective \"0,0 -40,20  0,199 -40,179  39,199 0,199  39,0 0,0\" ".
" ( front.png ".
" +distort Perspective \"0,0 0,0  0,199 0,199  149,199 99,169  149,0 99,30\" ".
" ) -background none -layers merge +repage -trim ";

system ("convert $cmd box_set.png ");
  
// Delete the tempory images
$delete = array( 'spine.png','front.png' );
foreach ( $delete as $value ) {
    unlink( $value );
}
exec won't return images on my machine so I had to convert those to system.

Any ideas what I can do to get this to work?

Thanks.

Tai

Re: Looking For Solution Input Please

Posted: 2008-09-03T17:57:52-07:00
by vendetta
Just to update this ...

I installed iMagick and this seems like it works pretty well, I copied an example for the site and it rendered perfectly the firs time.

Now, any advice on how to do a perspective transformation using iMagick?

There really isn't any documentation on that at the PECL site.

Thanks again.

T

Re: Looking For Solution Input Please

Posted: 2008-09-04T07:51:16-07:00
by Bonzo
A simpler version - I wonderd why I could not get it work forgetting my server is on a different version to my PC at home !!!

Code: Select all

<?php
$cmd = " -size 200x40 xc:lightblue ".
"-pointsize 20 -gravity north -annotate +5+0 \"Rubblewebs\" ".
" -pointsize 10 -gravity south -annotate +0+0 \"Website design\" ".
" -stroke blue -strokewidth 2 -draw \"line 30,0 30,40\"";
  
exec("convert $cmd spine.png ");

// COMENT OUT THE ONE YOU DO NOT WANT

// Older versions
$cmd =" spine.png -matte -virtual-pixel transparent ".
" -distort Perspective \"0,0 0,40 200,40 200,0 0,0 0,40 200,30 200,10\" ";

// Newer versions
$cmd =" spine.png -matte -virtual-pixel transparent ".
" -distort Perspective \"0,0 0,0 0,40 0,40 200,40 200,30  200,0 200,10\" ";

// Array for any errors
$array = array();
exec("convert $cmd distorted_spine.png 2>&1", $array); 
echo "<pre>".print_r($array); 
echo "</pre>";

?>

<img src="spine.png">
<img src="distorted_spine.png">
There is another section of the forum for Imagick questions.