gpt4 book ai didi

php - 圆形裁剪图像(php)

转载 作者:可可西里 更新时间:2023-11-01 12:32:03 26 4
gpt4 key购买 nike

以下代码可以在我的笔记本电脑上运行,但不能在远程服务器上运行:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$filename = "../../content/".base64_decode($_GET["file"]);


$ext = pathinfo($filename, PATHINFO_EXTENSION);

if ($ext=="jpg" || $ext=="jpeg") {
$image_s = imagecreatefromjpeg($filename);
} else if ($ext=="png") {
$image_s = imagecreatefrompng($filename);
}

$width = imagesx($image_s);
$height = imagesy($image_s);


$newwidth = 285;
$newheight = 232;

$image = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($image,true);
imagecopyresampled($image,$image_s,0,0,0,0,$newwidth,$newheight,$width,$height);

// create masking
$mask = imagecreatetruecolor($width, $height);
$mask = imagecreatetruecolor($newwidth, $newheight);



$transparent = imagecolorallocate($mask, 255, 0, 0);
imagecolortransparent($mask, $transparent);



imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent);



$red = imagecolorallocate($mask, 0, 0, 0);
imagecopy($image, $mask, 0, 0, 0, 0, $newwidth, $newheight);
imagecolortransparent($image, $red);
imagefill($image,0,0, $red);

// output and free memory
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($mask);
?>

它在我的笔记本电脑上显示了下图: http://i.stack.imgur.com/Aai1r.png

这是它在远程服务器上的显示方式: http://i.stack.imgur.com/77fbV.png

你怎么看?有什么问题吗?

最佳答案

更改行:

imagecopy($image, $mask, 0, 0, 0, 0, $newwidth, $newheight);

到:

imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100);

关于php - 圆形裁剪图像(php),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880503/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com