Verify ImageMagick installation

前端 未结 10 1522
一个人的身影
一个人的身影 2020-11-29 01:16

My web hosting said ImageMagic has been pre-installed on the server. I did a quick search for \"ImageMagick\" in the output of phpinfo() and I found nothing. I can\'t SSH in

10条回答
  •  旧巷少年郎
    2020-11-29 01:24

    EDIT: The info and script below only applies to iMagick class - which is not added by default with ImageMagick!!!

    If I want to know if imagemagick is installed and actually working as a php extension, I paste this snippet into a web accessible file

    newPseudoImage(50, 50, "gradient:red-black");
    
    /* Create imagickdraw object */
    $draw = new ImagickDraw();
    
    /* Start a new pattern called "gradient" */
    $draw->pushPattern('gradient', 0, 0, 50, 50);
    
    /* Composite the gradient on the pattern */
    $draw->composite(Imagick::COMPOSITE_OVER, 0, 0, 50, 50, $im);
    
    /* Close the pattern */
    $draw->popPattern();
    
    /* Use the pattern called "gradient" as the fill */
    $draw->setFillPatternURL('#gradient');
    
    /* Set font size to 52 */
    $draw->setFontSize(52);
    
    /* Annotate some text */
    $draw->annotation(20, 50, "Hello World!");
    
    /* Create a new canvas object and a white image */
    $canvas = new Imagick();
    $canvas->newImage(350, 70, "white");
    
    /* Draw the ImagickDraw on to the canvas */
    $canvas->drawImage($draw);
    
    /* 1px black border around the image */
    $canvas->borderImage('black', 1, 1);
    
    /* Set the format to PNG */
    $canvas->setImageFormat('png');
    
    /* Output the image */
    header("Content-Type: image/png");
    echo $canvas;
    ?>
    

    You should see a hello world graphic:

    enter image description here

提交回复
热议问题