distorting php string
Posted: 2011-02-04T06:44:05-07:00
Hi,
I'm trying to distort some text using imagemagick in php. But I can't figure out how to get imagemagick to read the string to be distorted, I can't turn it into an image at this point because I add the string to an image using "imagettftext" later on.
I receive the error: "Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `C:\wamp\www\h': No such file or directory' in C:\wamp\www\distort_test.php:20 Stack trace: #0 C:\wamp\www\distort_test.php(20): Imagick->__construct('h') #1 {main} thrown in C:\wamp\www\distort_test.php on line 20"
The code I'm trying to get to work is below. Any help would be hugely appreciated.
Thank you!
I'm trying to distort some text using imagemagick in php. But I can't figure out how to get imagemagick to read the string to be distorted, I can't turn it into an image at this point because I add the string to an image using "imagettftext" later on.
I receive the error: "Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `C:\wamp\www\h': No such file or directory' in C:\wamp\www\distort_test.php:20 Stack trace: #0 C:\wamp\www\distort_test.php(20): Imagick->__construct('h') #1 {main} thrown in C:\wamp\www\distort_test.php on line 20"
The code I'm trying to get to work is below. Any help would be hugely appreciated.
Thank you!
Code: Select all
<?php
{
$image = imagecreate(400, 200);
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefill($image, 0, 0, $white);
$letter1 = "abcdefghijklmnopqrstuvwxyz";
$letter2 = "abcdefghijklmnopqrstuvwxyz";
$text1 = "";
$text2 = "";
$text1 .= $letter1[rand(0,25)];
$text2 .= $letter2[rand(0,25)];
$font = 'Arial.ttf';
$im = new imagick($text1);
$im->distortImage( Imagick::DISTORTION_PERSPECTIVE,
array( 8, 40, 6, 30, 8, 126, 8, 126, 90, 126, 105, 126, 90, 5, 126, 30), true );
$im2 = new imagick(text2 );
$im2->distortImage( Imagick::DISTORTION_PERSPECTIVE,
array( 8, 40, 6, 30, 8, 126, 8, 126, 90, 126, 105, 126, 90, 5, 126, 30), true );
imagettftext($image, 14, 0, 50, 60, $black, $font, $im);
imagettftext($image, 14, 0, 90, 60, $black, $font, $im2);
imagepng($image);
imagedestroy($image);
header('Content-Type: image/png');
echo $image;
}
?>