将.png图片上传到我的网站时,图片是透明的,直到我全屏打开它,然后它才变成黑色。您能告诉我是否有任何代码错误,该如何解决?
$image_old = $this - > image;
$this - > image = imagecreatetruecolor($width, $height);
if (isset($this - > info['mime']) && $this - > info['mime'] == 'image/png') {
imagealphablending($this - > image, false);
imagesavealpha($this - > image, true);
$background = imagecolorallocatealpha($this - > image, 255, 255, 255,
127);
imagecolortransparent($this - > image, $background);
} else {
$background = imagecolorallocate($this - > image, 255, 255, 255);
}
imagefilledrectangle($this - > image, 0, 0, $width, $height, $background);
imagecopyresampled($this - > image, $image_old, $xpos, $ypos, 0, 0,
$new_width, $new_height, $this - > info['width'], $this - > info['height']);
imagedestroy($image_old);
$this - > info['width'] = $width;
$this - > info['height'] = $height;
}
public
function watermark($file, $position = 'bottomright') {
$watermark = $this - > create($file);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
switch ($position) {
case 'topleft':
$watermark_pos_x = 0;
$watermark_pos_y = 0;
break;
case 'topright':
$watermark_pos_x = $this - > info['width'] - $watermark_width;
$watermark_pos_y = 0;
break;
case 'bottomleft':
$watermark_pos_x = 0;
$watermark_pos_y = $this - > info['height'] - $watermark_height;
break;
case 'bottomright':
$watermark_pos_x = $this - > info['width'] - $watermark_width;
$watermark_pos_y = $this - > info['height'] - $watermark_height;
break;
}
imagecopy($this - > image, $watermark, $watermark_pos_x, $watermark_pos_y,
0, 0, 120, 40);
imagedestroy($watermark);
}
public
function crop($top_x, $top_y, $bottom_x, $bottom_y) {
$image_old = $this - > image;
$this - > image = imagecreatetruecolor($bottom_x - $top_x, $bottom_y -
$top_y);
imagecopy($this - > image, $image_old, 0, 0, $top_x, $top_y, $this -
>
info['width'], $this - > info['height']);
imagedestroy($image_old);
}
public
function rotate($degree, $color = 'FFFFFF') {
$rgb = $this - > html2rgb($color);