現在、最低品質の透過pngを作成したいと考えています。
コード:
<?php
function createImg ($src, $dst, $width, $height, $quality) {
$newImage = imagecreatetruecolor($width,$height);
$source = imagecreatefrompng($src); //imagecreatefrompng() returns an image identifier representing the image obtained from the given filename.
imagecopyresampled($newImage,$source,0,0,0,0,$width,$height,$width,$height);
imagepng($newImage,$dst,$quality); //imagepng() creates a PNG file from the given image.
return $dst;
}
createImg ('test.png','test.png','1920','1080','1');
?>
ただし、いくつかの問題があります。
新しいファイルを作成する前に、png ファイルを指定する必要がありますか? または、既存のpngファイルなしで作成できますか?
警告: imagecreatefrompng(test.png): ストリームを開けませんでした: そのようなファイルまたはディレクトリはありません
C:\DSPadmin\DEV\ajax_optipng1.5\create.php 4行目
エラーメッセージがありますが、それでもpngファイルが生成されますが、ファイルが黒色の画像であることがわかりました。透明にするためにパラメータを指定する必要がありますか?
ありがとう。