添加图片(PNG / JPG)到动画gif(PHP iMagick)

时间:2015-10-20 13:55:08

标签: php imagemagick imagick animated-gif

我正在使用 imagick(PHP)版本来基本上为动画gif添加文字和徽标。我设法添加了很棒的文字。但我正在努力使用以下内容添加图像:

    $gif = new Imagick();
    $gif->readImage('images/highres/bg/' . $bgimg . '.gif');
    foreach ($gif as $frame) {
        $img = new Imagick(); 
        $img->readImageBlob($frame);
        $canvas->addImage( $img );  
      //$canvas->compositeImage($img, Imagick::COMPOSITE_DEFAULT, 0, 0); NOT WORKING
        $canvas->setImageDelay( $img->getImageDelay() ); 
    //$img->clear();
    //Add Logo
    //$logo         = new Imagick();
    //$logo->readImage('images/uploads/155x100.jpg');
    //$canvas->compositeImage($logo, Imagick::COMPOSITE_DEFAULT, 500, 500); NOT WORKING
    //$canvas->addImage( $logo ); 
}

此外,我正在努力使用 X,Y坐标进行定位。

有什么想法吗?

1 个答案:

答案 0 :(得分:-2)

这可以帮到你。

<?php
if (isset($_FILES["file"])) {
    $tmpFile = $_FILES["file"]["tmp_name"];
    $fileName = ... // determine secure name for uploaded file

    list($width, $height) = getimagesize($tmpFile);
    // check if the file is really an image
    if ($width == null && $height == null) {
        header("Location: index.php");
        return;
    }
    // resize if necessary
    if ($width >= 400 && $height >= 400) {
        $image = new Imagick($tmpFile);
        $image->thumbnailImage(400, 400);
        $image->writeImage($fileName);
    }
    else {
        move_uploaded_file($tmpFile, $fileName);
    }
}