Hello People here is my code below...
$width = 1200;
$height = 100;
$output="C:\wamp\www\latest\im\arc.gif";
try
{
$pixel = new ImagickPixel( "lightblue" );
$text = 'srinivas';
$arcArray = array(360);
$draw1 = new ImagickDraw();
$draw1->setFont('Arial');
$draw1->setFontSize( 120 );
$draw1->setGravity( Imagick::GRAVITY_WEST );
$draw2 = new ImagickDraw();
$draw2->setFont('Arial');
$draw2->setFontSize( 120 );
$draw2->setGravity( Imagick::GRAVITY_EAST );
$im1 = new Imagick();
$im1->newImage($width, $height, $pixel);
$im1->annotateImage($draw1, 0, 0, 0, $text);
$im1->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_WHITE );
$im1->distortImage( Imagick::DISTORTION_ARC, $arcArray, false );
$im2 = new Imagick();
$im2->newImage($width, $height, $pixel);
$im2->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_WHITE );
$im2->distortImage( Imagick::DISTORTION_ARC, $arcArray, false );
$im2->annotateImage($draw2, 0, 0, 0, $text);
$frame = new Imagick();
$frame->readImageBlob($im2);
for ($i = 1; $i < 3; ++$i) {
$frame = new Imagick();
$GIF = new Imagick();
$frame->readImageBlob(${'im'.$i});
$frame->setImageDispose(2);
$frame->setImageDelay(100);
$GIF->addImage($frame);
$GIF->setImageDelay(100);
}
$frame->writeImages("C:\wamp\www\latest\im\arc.gif" , true);
}
catch(Exception $e)
{
echo $e->getMessage();
}
Iam getting exception error message Zero size image string passed
what iam trying to do is very simple,Iam creating two images one with the position $draw1->setGravity( Imagick::GRAVITY_WEST );
and the other text with the position $draw1->setGravity( Imagick::GRAVITY_EAST );
, within the same arc created...how to fix this?
There's a few issues with sample code provided.
First
Image $im2
will need to call annotateImage
before distortImage
, or your text will float outside of the arc
$im2->annotateImage($draw2, 0, 0, 0, $text);
$im2->distortImage( Imagick::DISTORTION_ARC, $arcArray, false );
Second
The error message of "Zero size image string passed" will occur, as $im2
hasn't been given any format/context. Such that (string)$im2
will result in an empty string. Fix this by setting the image format
$im2->setImageFormat('gif');
// ...
$frame->readImageBlob($im2);
The behavior of Imagick::readImageBlob(Imagick)
is a little confusing to read. A clean solution would be to define the images blob.
$blob = $im2->getImageBlob();
$frame->readImageBlob($blob);
Third
I'm also confused by the for
loop. Whatever you've declared as $frame
seems to be overwritten with each iteration, and the $GIF
images doesn't appear to be doing anything. I'll assume you simply want to create an animated gif; which, would only require one instance of $frame
.
$frame = new Imagick();
$im2->setImageFormat('gif');
$frame->readImageBlob($im2->getImageBlob());
for ($i = 1; $i < 3; ++$i) {
$frame->addImage(${'im'.$i});
$frame->setImageDelay(100);
}
$frame->setImageDispose(2);
$frame->setImageIterations(0);
$frame->writeImages("C:\wamp\www\latest\im\arc.gif" , true);