Creating a watermark on image using imagecopy function by the PHP
imagecopy ( resource
Sample Code:
<?php
// Load the stamp and the photo to apply the watermark to
//watermark image that you want to see on top of the other image
//image format can be jpeg,png,gif but png is recomnded
$stamp = imagecreatefrompng('stamp.png');
//Base image
$im = imagecreatefromjpeg('test.jpeg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_left = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_left, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/gif');
imagepng($im);
imagedestroy($im);
?>
Images used:
imagecopy ( resource
$dst_im
, resource $src_im
, int $dst_x
, int $dst_y
, int $src_x
, int $src_y
, int $src_w
, int $src_h
)dst_im
Destination image link resource.
src_im
Source image link resource.
dst_x
x-coordinate of destination point.
dst_y
y-coordinate of destination point.
src_x
x-coordinate of source point.
src_y
y-coordinate of source point.
src_w
Source width.
src_h
Source height.
<?php
// Load the stamp and the photo to apply the watermark to
//watermark image that you want to see on top of the other image
//image format can be jpeg,png,gif but png is recomnded
$stamp = imagecreatefrompng('stamp.png');
//Base image
$im = imagecreatefromjpeg('test.jpeg');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_left = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($im, $stamp, imagesx($im) - $sx - $marge_left, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
// Output and free memory
header('Content-type: image/gif');
imagepng($im);
imagedestroy($im);
?>
Images used:
Result:
No comments:
Post a Comment