在圆中裁剪图像(php) [英] Crop image in circle (php)

查看:66
本文介绍了在圆中裁剪图像(php)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码可在笔记本电脑上使用,但不能在远程服务器上使用:

The following code works on my laptop but doesn't work on remote server:

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

It shows the following image on my laptop: http://i.stack.imgur.com/Aai1r.png

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

And this is how it's shown on remote server: http://i.stack.imgur.com/77fbV.png

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

What do you think? What's a problem?

推荐答案

更改了这一行:

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

收件人:

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

这篇关于在圆中裁剪图像(php)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆