dtlab08822 2014-04-25 09:21
浏览 95
已采纳

想象代码 - ImageMagick无法正常工作

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?

  • 写回答

1条回答 默认 最新

  • dty63504 2014-04-25 14:06
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考