我的代码工作正常,但有一个问题,我无法获取图片网址,只有我获得网站网址。我需要这个示例网址:http://example.com/image.png
带水印。
我想在这里获得直接水印图片网址<img src="http://example.com/image.png"/>
代码:
<?php
$logo = 'http://www.slatecube.com/images/play-btn.png';
$img = 'http://i.imgur.com/GMjqTR7.jpg';
// Load the image where the logo will be embeded into
$image = imagecreatefromjpeg($img);
// Load the logo image
$logoImage = imagecreatefrompng("$logo");
imagealphablending($logoImage, true);
// Get dimensions
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$logoWidth=imagesx($logoImage);
$logoHeight=imagesy($logoImage);
// Paste the logo
imagecopy(
// destination
$image,
// source
$logoImage,
// destination x and y
($imageWidth-$logoWidth)/2, ($imageHeight-$logoHeight)/2,
// source x and y
0, 0,
// width and height of the area of the source to copy
$logoWidth, $logoHeight);
// Set type of image and send the output
header("Content-type: image/png");
imagePng($image);
// Release memory
imageDestroy($image);
imageDestroy($imageLogo);
?>
答案 0 :(得分:0)
你需要使用.htaccess。 .htaccess将改变路线行为。当你调用一个图像时,它实际上是一个php文件。这是一个例子。
<强>的.htaccess 强>
RewriteEngine on
RewriteBase /
RewriteRule ^(.*\.(gif|jp?g|png))$ img.php?imageName=$1 [NC]
对您的代码进行一些更改......
<?php
$logo = 'ico.png';
// I used a folder for images here
$img = 'images/' . $_GET['imageName']; // it's a classic GET var
//... after these changes add your code...