你能支持我吗?我有下面的脚本,以创建一个缩略图,工作良好!但是,当我上传一个透明背景的PNG文件时,由于某种原因,背景变成了黑色。
<?php
// Function for resizing jpg, gif, or png image files
function ak_img_resize($target, $newcopy, $w, $h, $ext) {
list($w_orig, $h_orig) = getimagesize($target);
$scale_ratio = $w_orig / $h_orig;
if (($w / $h) > $scale_ratio) {
$w = $h * $scale_ratio;
} else {
$h = $w / $scale_ratio;
}
$img = "";
$ext = strtolower($ext);
if ($ext == "gif"){
$img = imagecreatefromgif($target);
} else if($ext =="png"){
$img = imagecreatefrompng($target);
} else {
$img = imagecreatefromjpeg($target);
}
$tci = imagecreatetruecolor($w, $h);
// imagecopyresampled(dst_img, src_img, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h)
imagecopyresampled($tci, $img, 0, 0, 0, 0, $w, $h, $w_orig, $h_orig);
imagejpeg($tci, $newcopy, 80);
}
?>
如果PNG的背景是透明的,我需要缩略图也是透明的,你能支持我吗?任何帮助将是伟大的!
Thanks in advance
尝试替换:
imagejpeg($tci, $newcopy, 80);
由:imagegif($tci, $newcopy, 80);
或根据图像格式的等效函数:
Imagepng
Imagegif
Imagejpeg
Imagebmp
Using:
$tci = imagecreate($w, $h);
:
$tci = imagecreatetruecolor($w, $h);
我的问题现在解决了:)