6

ばかげた質問だと思いますが、PHPと画像処理を扱うのは初めてです。要するに、ウェブページにエコーするのではなく、どうすれば画像を保存できるのだろうか。このコードは、この質問では重要ではないかもしれない画像を歪めるためのものです。画像を保存すると、最後の数行が表示されます..

コード:

/* Create new object */
$im = new Imagick('my_img.png');


$width = $im->getImageWidth();
$height = $im->getImageHeight();

/* Set the image format to png */
$im->setImageFormat('png');

/* Fill new visible areas with transparent */
$im->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);

/* Activate matte */
$im->setImageMatte(true);

/* Control points for the distortion */
$controlPoints = array( 0, 0, 
                    $height*0.7, $height*0.3,

                    0, $height,
                    0, $height,

                    $width, 0,
                    $height*0.7+$width, $height*0.3,

                    $width, $height,
                    $width, $height);

/* Perform the distortion */                       
$im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);

/* Ouput the image */ 
//commented out because I want to save the image instead
//header("Content-Type: image/png");
//echo $im;

// right way to save image?
imagepng($im, 'new_image.png');

// Free up memory
imagedestroy($im);

私が得るエラー:imagepng():指定された引数は有効な画像リソースではありません...

4

1 に答える 1

13

交換

imagepng($im, 'new_image.png');

$im->writeImage('new_image.png');
于 2013-06-16T04:29:14.087 に答える