使用php进行水印和调整大小

时间:2014-03-15 16:17:17

标签: php gd

我试图对图像进行水印和调整大小但是我在调​​整大小部分时做错了任何帮助请

$image = @imagecreatefromjpeg('15_pic1.jpg');
$watermark = @imagecreatefrompng('watermark.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth));
$startheight = (($imageheight - $watermarkheight));
imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); 

//resize 
list($width, $height) = getimagesize($image);
imagecopyresized($thumb, $image, 0, 0, 0, 0, 300, 300, $width, $height);

header("Content-type: image/jpeg"); imagejpeg($thum); 
imagedestroy($image);
imagedestroy($watermark);

1 个答案:

答案 0 :(得分:1)

在这里工作的是代码

$img = "15_pic1.jpg";
$wat = "watermark.png" ;
$wit = "300";
$hei = "300";

$imagestart = @imagecreatefromjpeg($img);
$watermark = @imagecreatefrompng($wat);
list($width, $height) = getimagesize($img);
$imagewidth = imagesx($imagestart);
$imageheight = imagesy($imagestart);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth));
$startheight = (($imageheight - $watermarkheight));
imagecopy($imagestart, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight); 
$thumb = imagecreatetruecolor($wit, $hei);
imagecopyresized($thumb, $imagestart, 0, 0, 0, 0, $wit, $hei, $width, $height);
header("Content-type: image/jpeg"); imagejpeg($thumb); 
imagedestroy($image);
imagedestroy($watermark);
imagedestroy($thumb);