PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, October 11, 2022

[FIXED] How do I watermark an image?

 October 11, 2022     gd, php     No comments   

Issue

I have a jpg file that i want to merge another image png file on it. I am not sure how to implement this using php?


Solution

you can use gd's imagecopy function.

This function is used to copy a portion of image from source to the destination

imagecopy ( 
           $dst_im ,   // destination image (resource), imagecreatefrom(gif|jpg|png)
           $src_im ,   // destination image (resource), imagecreatefrom(gif|jpg|png) 
           $dst_x ,    // x cordinate in destination where u want the new obj placed
           $dst_y ,    // y cordinate in destination where u want the new obj placed
           $src_x ,    // x cordinate in source from wher u want the new obj placed
           $src_y ,    // y cordinate in source from where u want the new obj placed
           $src_w ,    // the width of the object to copy
           $src_h      // the height of the object to copy
);

As pointed in the comment in the above code, you will have to create an image resource for both destination and source.

Typically done using

 $src = imagecreatefromjpg('image.jpg');
 $dst = imagecreatefromjpg('watermark');

The remaining portions are just simple co-ordinates.

Also don't forget to visit imagecopy yourself.



Answered By - Kishor Kundan
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing