|带有内置水印的图像

时间:2019-01-17 07:34:40

标签: php

我使用以下著名代码获取带有内置水印的图像:

<?php
$filename=$_REQUEST['filename'];
$imgpath="images/";
$imgpath = $imgpath.$filename;
header('content-type: image/jpeg');
$watermarkfile="images/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);
?>

有效。但是我决定稍微复杂一些。我在同一目录中创建了一个fext.txt文件,内容如下:

blahblah.png
watermark.png
blahblah.png

我更改后的代码:

<?php
$filename=$_REQUEST['filename'];
$imgpath="images/";
$imgpath = $imgpath.$filename;
header('content-type: image/jpeg');
$myFile = "text.txt";
$lines = file($myFile);
$edno = $lines[1];
$watermarkfilе="images/";
$watermarkfile = $watermarkfilе.$edno;
$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);
?>

它不起作用-它返回主图像,但没有水印。在error_log中写道:

PHP Warning:  imagecreatefrompng(images/watermark.png): failed to open     stream: No such file or directory in /home/mysite/public_html/opit9    /watermark.php on line 11

我的问题是我错了哪里?预先感谢您的任何意见。

0 个答案:

没有答案