Watermarking an image with php, full code in here =)
O wrote this code to overlay 1 image over the other one... For some reason firefox reports that there is an error in the image and cannot be displayed.
Any clue?开发者_如何学JAVA
// yeah.php
error_reporting(E_ALL);
// A FUNCTION TO ADD THE OVERLAY
// SEE http://php.net/manual/en/function.imagealphablending.php#77085
function imagelogo(&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h) {
ImageAlphaBlending($dst_image, TRUE);
ImageAlphaBlending($src_image, TRUE);
ImageCopy($dst_image, $src_image, 0, ($dst_h - $src_h), 0, 0, $src_w, $src_h);
}
// LOCATION OF THE IMAGES (COULD COME IN FROM $_GET URL STRING)
$original = 'http://www.someurl.com/avatar/f22b5cb6587140ba89fa96a616ac7d5b?s=100&r=r';
$overlay = 'http://www.someurl.com/codenameT/overlay.png';
// READ THE IMAGE AND THE OVERLAY FILE
// MAN PAGE http://php.net/manual/en/function.imagecreatefrompng.php
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($overlay);
// ADD OVERLAY USING LOCAL FUNCTION
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));
// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);
Comment from neworld helped, i figure out that the url i was getting the image from was in JPG and it is required a PNG for the functions in my code to work.
精彩评论