Thursday, June 02, 2011

php Image Magik - how to force Text Wap without cropping

After several hours of trying to find the best way to add 2 sets of text to an image using ImageMagik without overlapping. The image is split into two natural text blocks. I felt it was easier to add the two sections of text to the one image instead of combining two images.

The simplest way I could find is to figure out the font point size and approximate the dimensions by the number of characters in your string. Then use the php wordwrap function to add newline characters every 35 characters.

Note: I only needed to force word wrapping on message one because it shows on the left side of the image. ImageMagik will automatically wrap the annotation if it runs into the right edge of the image. Well it appears that way and its working so far, but I may change it later just cause :)

//force text wrapping every 35 characters
$message = wordwrap($message, 35, "\n", true);
$filepath = '/home/';
$newfile = $filepath.'uploads/files/'.$newfilename;
//image we want to write text on
$blankfile = $filepath.'images/blank_image.png';

$imageCMD = "convert  '$blankfile'    ".
                 " -fill '#000000' -pointsize 16   -annotate +40+80 '$message1'   ".  
                 " -fill '#000000' -pointsize 20   -annotate +340+150 '$message2' ".
                 " '$newfile'" ;
//calls the linux commandline to process the command    
$cr = system( $imageCMD  , $retval);

Stumble Upon CodePyro

1 comment:

Benny said...

I will state which customized hublot replica sale through Rau-Tech begin from regarding 13, 000 Pounds as well as can move up in order to 20, 000 Pounds. Customized rolex replica as well as GMT Grasp II versions within precious metal instances price regarding thirty-three, 000 thirty six, 000 Pounds. Higher-end rolex replica uk versions within precious metal along with expensive diamonds, like the Rolex Pearlmaster along with Rau-Tech personalization price close to forty five, 500 Pounds. Every task is exclusive, that is precisely what rolex replica sale expectations to complete using the support. That's, to mix the actual benefit of rolex replica. In 2012, Rolex launched the uncommon completely new design using the Sky-Dweller watch loved ones debuted right here. We state "rare" simply because it's not typical with regard to Rolex release a an entirely brand new group of rolex replica uk along with additionally a brand new title.

Post a Comment