douxiuar885064 2014-12-08 09:04
浏览 44

运行php脚本在图像上添加水印时出现内部服务器错误

Am developing new photography website in which images are uploaded frequently.... Now I want to add watermark on uploaded images before it goes to client side, I have used the following code for watermark

$SourceFile = "sys\img\image1.jpg";
$DestinationFile = "sys\img\image1-wm.jpg"; 
$WaterMarkText = 'Copyright sys.com';
watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);

function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) { 
 list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); 
$black = imagecolorallocate($image_p, 0, 0, 0);
$font = 'arial.ttf';
$font_size = 10; 
imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
if ($DestinationFile<>'') {
   imagejpeg ($image_p, $DestinationFile, 100); 
} else {
   header('Content-Type: image/jpeg');
  imagejpeg($image_p, null, 100);
};
imagedestroy($image); 
imagedestroy($image_p); 
};

But it showing the following error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your 
request.
Please contact the server administrator to inform of the time the error occurred and of anything
you might have done that may have caused the error.

More information about this error may be available in the server error log.

What is the mistake I have done...?

  • 写回答

1条回答 默认 最新

  • drcmue4619 2014-12-08 10:39
    关注

    Finally I found an another way to add watermark to my images...

    Here is the code for watermark....

    $filename=$_REQUEST['filename'];
    $imgpath="img/"; // Folder of your images in the server
    $imgpath = $imgpath.$filename;
    header('content-type: image/jpeg'); //HTTP header - assumes your images in the gallery are JPGs
    $watermarkfile="img/watermark.png";
    $watermark = imagecreatefrompng($watermarkfile);
    list($watermark_width,$watermark_height) = getimagesize($watermarkfile);
    $image = imagecreatefromjpeg($imgpath);
    $size = getimagesize($imgpath);
    $dest_x = $size[0] - $watermark_width - 15;
    $dest_y = $size[1] - $watermark_height - 15;
    imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
    

    Save this code as watermark.php and then use it in the img tag as follows...

    <img src="watermark.php?filename=image1.jpg">
    

    Thats it... Working fine...

    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?