Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Tuesday, February 27, 2018

How to create a watermark on image using PHP?

Creating a watermark on image using imagecopy function by the PHP

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.
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:





Result:

8 comments:

  1. This post is really the best on this valuable topic.

    ReplyDelete
  2. Thanks for sharing such great piece of information with us. Digital Signature Certificate

    ReplyDelete
  3. Thanks For Sharing This, Very Interesting And Helpful Support Provide By this blog, This was the first news blog. Digital Signature Certificate

    ReplyDelete
  4. I am very grateful you did share your knowledge here. It is an excellent post.sharing this sort of educational posts. Apply Class 3 Digital Signature Certificate

    ReplyDelete
  5. Thank you so much for providing such useful content. Thanks very nice share. Class 2 Digital Signature Certificate

    ReplyDelete

More Posts

FOLLOW