• Sign Up
    • OpenID
    • Google
    • Yahoo!
    • Facebook
    • Ning
  • Discuss
  • New Topic
  • Categories
  • Forum
  • Debate
  • Languages
    • English
    • Finnish
    • Arabic
    • Italian
    • Korean
    • French
    • Chinese(Traditional)
    • Chinese(Simplified)
    • Swedish
    • Czech
    • Hindi
    • Dutch
    • Norwegian
    • Russian
    • Croatian
    • German
    • Japanese
    • Bulgarian
    • Portuguese
    • Chinese
    • Spanish
    • Greek
  • Login

Ok

Ads

affordable seo

Ask a Question



Welcome New Members!

zhangwigs

chandan...

jimmy b...

moneyma...

stacyjohn

Emile

Tiffany

CBIL360

Lawsons

christi...

meiwei

kingkhan

brendaj...

swati

sunnyjohn

conniejohn

sunnyping

fengmi

califor...

hengjiao


Hot Topics

array code column content Custom database drupal element field file form function index jquery module MySQl node page PHP query server something SQL string table theme time user VALUE way

 

 

 

Reason

 

How To Add Watermark To An Image with PHP and Imagepng

Jaan

Jaan
Hey!

Now I'm going to teach you how to add a watermark to an image.
It is really easy.

It does like this:

First lets define our image where we want our watermark:


$image = 'path/to/a/file.jpg';
 


Now we need to check what kind of image is it and set it up for processing:


if(eregi('.jpg', $image)) {
   
    $i = imagecreatefromjpeg($image);
   
}elseif(eregi('.gif', $image)) {
   
    $i = imagecreatefromgif($image);
   
}elseif(eregi('.png', $image)) {
   
    $i = imagecreatefrompng($image);
   
}
 


Now let's take our watermark:


$watermark = imagecreatefromgif('watermark.gif');
 


Next is taking width and height of our image and our watermark:


$width = imagesx($i);
$height = imagesy($i);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
 


And now is the time for the most important step, putting those images together:


imagecopymerge($i, $watermark, (($width - $watermark_width)), (($height - $watermark_height)), 0, 0, $watermark_width, $watermark_height, 50);
 


If it's done, then we want to display our watermarked image:


if(eregi('.jpg', $image)) {
   
    header('Content-Type: image/jpeg');
    imagejpeg($i);
   
}elseif(eregi('.gif', $image)) {
   
    header('Content-Type: image/gif');
    imagegif($i);
   
}elseif(eregi('.png', $image)) {
   
    header('Content-Type: image/png');
    imagepng($i);
   
}
 


Now when everything is done, let's destroy our images:


imagedestroy($i);
imagedestroy($watermark);
 


And we are done! :) If everything went well it should look like this:

C Ca B L

Here's the full code:


<?php

/**
 * @author Jaan
 * @link http://webhostingtalkforums.com
 * @copyright 2011
 */


$image = 'battlefield.jpg';

if(eregi('.jpg', $image)) {
   
    $i = imagecreatefromjpeg($image);
   
}elseif(eregi('.gif', $image)) {
   
    $i = imagecreatefromgif($image);
   
}elseif(eregi('.png', $image)) {
   
    $i = imagecreatefrompng($image);
   
}

$watermark = imagecreatefromgif('watermark.gif');

$width = imagesx($i);
$height = imagesy($i);
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
imagecopymerge($i, $watermark, (($width - $watermark_width)), (($height - $watermark_height)), 0, 0, $watermark_width, $watermark_height, 50);


if(eregi('.jpg', $image)) {
   
    header('Content-Type: image/jpeg');
    imagejpeg($i);
   
}elseif(eregi('.gif', $image)) {
   
    header('Content-Type: image/gif');
    imagegif($i);
   
}elseif(eregi('.png', $image)) {
   
    header('Content-Type: image/png');
    imagepng($i);
   
}

imagedestroy($i);
imagedestroy($watermark);

?>
 


I hope it helped you. If you have questions feel free to post a comment below.

I will safely get you 1500 or more fast and REAL YouTube views on your video in 24 hours from the United States to boost yourself or business~~!!~~ for $12


In PHP | 4 Replies | 10637 Views | 1 month ago
watermark define taking width images
  • Report Abuse
  • Email
  • Add to Favorites

Rate Now:   1 2 3 4 Average Rating: 0.00 / 1 ratings


Replies:

Guest

Guest
Thanks! It helped me a lot.

  • Reply to Answer
  • 1 month ago
  • Report Abuse
  • By Guest

Rate Now: 1 2 3 4 Average Rating: 0.00 / 0 ratings

Replied by Guest 1 month ago

Guest

Guest
hyaiuqiqjogpsnfs, <a href="http://www.ycasscmlwa.com">pcranhikiv</a>

  • Reply to Answer
  • 1 month ago
  • Report Abuse
  • By Guest

Rate Now: 1 2 3 4 Average Rating: 0.00 / 0 ratings

Replied by Guest 1 month ago

Guest

Guest
ktriqqiqjogpsnfs, <a href="http://www.eaolzjosvo.com">fpcigzdgsh</a>

  • Reply to Answer
  • 1 month ago
  • Report Abuse
  • By Guest

Rate Now: 1 2 3 4 Average Rating: 0.00 / 0 ratings

Replied by Guest 1 month ago

Guest

Guest
avfniqiqjogpsnfs, http://www.axbkvbesxk.com dkblcrbusc

  • Reply to Answer
  • 1 month ago
  • Report Abuse
  • By Guest

Rate Now: 1 2 3 4 Average Rating: 0.00 / 0 ratings

Replied by Guest 1 month ago


Your Response:

Join

Login


 

Related Questions

Can I not just do $_FILES['image']=$image and put $image into a database?
0 Answers | 3364 Views
Whats a good way to reload an image in jQuery?
0 Answers | 4474 Views
Is there a preferred jquery plugin for ajax image/file uploads?
0 Answers | 4579 Views
How do I manually create thumbnails of an image?
1 Answer | 2914 Views
Is there a way to add input fields to the 'edit image details' form?
0 Answers | 2863 Views
Disclaimer | Privacy Policy | Terms | ■ RSS | Sitemap | Contact Us | ■ Invite | Create your Widget | ■ Twitter | ■ Facebook
© 2013 PHPInformer. All rights reserved

PHPInformer does not evaluate or guarantee the accuracy of any PHPInformer content. Click here for the Full Disclaimer.