圆形裁剪图像(php)

圆形裁剪图像(php),php,gd,Php,Gd,以下代码适用于我的笔记本电脑,但不适用于远程服务器: <?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 = i

以下代码适用于我的笔记本电脑,但不适用于远程服务器:

<?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);
?>

它在我的笔记本电脑上显示以下图像:

这是它在远程服务器上的显示方式:


你觉得怎么样?有什么问题吗?

我想您的文件路径可能有问题。检查pathinfo是否返回有效的扩展名,并在$filename声明后添加一些内容以检查它是否存在且可读

if(!is_file($file) || !is_readable($file)){ die('Readable file not found');}

我认为一本关于如何调试的基本读物会对您有所帮助,并帮助您解决问题

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


您的服务器上的GD版本是否与您的本地环境不同?这几乎肯定是问题所在。它还可能链接到transparency.local env具有GD 2.0版本,并且在服务器2.0.38上。两人都支持透明性。这样的宝石会在评论中消失。很有趣的阅读。
imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth, $newheight,100);