Scale and Watermark Images PHP


Published on

Learn the how to create watermark on an image using text or another image. Also learn how to scale images to different sizes.

Published in: Technology, Art & Photos
  • i want to ,join two images using ffmpeg in php.
    Are you sure you want to  Yes  No
    Your message goes here
  • Watermarking an image in PHP is very easy. If you follow the code below, you can do it in 2 minutes.

    ”) {

    imagejpeg ($image_p, $DestinationFile, 100);

    } else {

    header(‘Content-Type: image/jpeg’);

    imagejpeg($image_p, null, 100);


    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Scale and Watermark Images PHP

  1. 1. Scaling and Watermarking Images
  2. 2. OverviewObjectiveLearn the how to create watermark on an image using text oranother image. Also learn how to scale images to differentsizes.Requirements Understanding of Image Basics Installed version of ImagickEstimated Time10 minutes
  3. 3. Follow Along With A Code Example1. Download a copy of the example code at Install the system in an environment you feel comfortable testing in.3. Proceed to examples/avi/ScaleandWatermarkImage.php
  4. 4. Scaling An Image To start this store we need an image to scale. First we are going to define our image and afterwards we are going to scale it too different sizes using PVImage::scaleImage.1. Define the image and pass the 2. Set the new width 3. Set the new heightimage location as an argument 4. The location of the scaled image
  5. 5. Scaled ImagesThe scaled images should look something similar tobelow. Both of these are much smaller than the original.
  6. 6. Scaling With Options Depending on the scenario, such as images stored as bytes in the database, you might receive the image a string in php. This is not a problem, we just set the type to blob.1. Read the image in from a file as a string 2. Set the file option to ‘blob’ for images in blob/bytes/string format3. Use a defined image name instead of a random Do not add an extension to the filename
  7. 7. Scaled With Options 2 Now that we have our options set, we can scale the image from the bytes read from the file, and write it out to file.1. Pass in the bytes string from the file 2. Set the width and height 3. Pass in the options
  8. 8. Watermark with Text Add we move on watermarking images. Watermarking with text is relatively simple. All we need is the image to watermark and a string of text.1. Location of the image 2. Text to place as a watermark
  9. 9. Watermarked ImageOur watermarked image, without any modifications, willlook like below.
  10. 10. Text Watermarking with Options Our previous example of watermarking can be a little bland. With some options, we can add some style to the watermarks.1. Read the image in as bytes 2. Change the font color 3. Rotate the text 4. Offset the set 5. Set the name of the file 6. Use blob for byte input
  11. 11. Watermarked Image with Flavor Pass in the variables and we should get back our image with an altered text watermark.1. Pass in the image bytes 2. Set the text 3. Pass in the options
  12. 12. Watermark with ImageOur final demonstration in this tutorial is watermarking withanother image. What the methodwatermarkImageWithImage() really does is combine twoimages together. In our example we use a smaller image of thesame image, but in production environment, it is suggested to avery light image.
  13. 13. Two Images CombinedBelow is how the images looked combine. Replace withyour own image and change the offset to customize thewatermark.
  14. 14. Review1. Scale an image using the PVImage::scaleImage() method.2. Watermark an image with text using the PVImage::watermarkImageWithText() method3. Watermark/Combine two image with another image using PVImage::watermarkImageWithImage() method.
  15. 15. API ReferenceFor a better understanding of the image manipulation, checkout the api at the two links below.PVImage More Tutorials For more tutorials, please visit: