2012-07-30 63 views
-2

我使用PHP,我想帮助用户使用PHP剪切他们的图像的工具。 当用户上传图像时,会保存它(例如image1.png)。我想知道是否有一个功能允许我这样做。我有什么要做的例如,如果我想剪切宽度和高度200px,并使其具有100px宽度的image1.png?编辑图像使用PHP

谢谢你的时间!

+3

当然可以。你有什么尝试? – j08691 2012-07-30 15:52:23

+0

是的,可能 - http://www.php.net/manual/en/function.imagecreatefrompng.php – 2012-07-30 15:53:31

+1

我还没有尝试过任何东西。我在这个论坛和谷歌搜索它,但我无法找到答案。 – 2012-07-30 15:54:04

回答

1
function setImage($image) 
{ 

//Your Image 
$this->imgSrc = $image; 

//create image from the jpeg 
this->myImage = imagecreatefromjpeg($this->imgSrc) or die("Error: Cannot find image!"); 

$this->cropWidth = 100; 
$this->cropHeight = 200; 


//getting the top left coordinate 
$this->x = 0; 
$this->y = 0;   
} 

function createThumb() 
{ 

$this->thumb = imagecreatetruecolor(100, 200); 

imagecopyresampled($this->thumb, $this->myImage, 0, 0,$this->x, $this->y, 100, 200, $this->100, $this->200); 

} 

function renderImage() 
{ 

header('Content-type: image/jpeg'); 
imagejpeg($this->thumb); 
imagedestroy($this->thumb); 

} 

$image = new cropImage; 
$image->setImage($src); 
$image->createThumb(); 
$image->renderImage(); 

http://www.talkphp.com/advanced-php-programming/1709-cropping-images-using-php.html

编辑带到满足您的特定需求。访问链接以获得PHP裁剪的全面概述。