Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 455233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:21:01+00:00 2026-05-12T22:21:01+00:00

i am using this code to create watermark. $image = ‘1.jpg’; $overlay = ‘stamp.png’;

  • 0

i am using this code to create watermark.

    $image = '1.jpg';
    $overlay = 'stamp.png';
    $opacity = "20";
    if (!file_exists($image)) {
        die("Image does not exist.");
    }
    // Set offset from bottom-right corner
    $w_offset = 0;
    $h_offset = 100;
    $extension = strtolower(substr($image, strrpos($image, ".") + 1));
    // Load image from file
    switch ($extension)
    {
        case 'jpg':
        $background = imagecreatefromjpeg($image);
        break;
        case 'jpeg':
        $background = imagecreatefromjpeg($image);
        break;
        case 'png':
        $background = imagecreatefrompng($image);
        break;
        case 'gif':
        $background = imagecreatefromgif($image);
        break;
        default:
        die("Image is of unsupported type.");
    }
    // Find base image size
    $swidth = imagesx($background);
    $sheight = imagesy($background);
    // Turn on alpha blending
    imagealphablending($background, true);
    // Create overlay image
    $overlay = imagecreatefrompng($overlay);
    // Get the size of overlay
    $owidth = imagesx($overlay);
    $oheight = imagesy($overlay);
    // Overlay watermark
    imagecopymerge($background, $overlay, $swidth - $owidth - $w_offset, $sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight, $opacity);
    imagejpeg($background,$image);
    // Destroy the images
    imagedestroy($background);
    imagedestroy($overlay);

the png image contains a text with all other region as transparent.
but when i execute this code , it applys the png over jpg, but the transparecy is not maintained of the png. it shows in a box.

how can i acheive that . ie if a png contains transaparent part , it should show the below image in that part….?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:21:01+00:00Added an answer on May 12, 2026 at 10:21 pm

    replacing imagecopymerge with imagecopy solved the issue. here is the new code

    function watermark($image){
        $overlay = '../../../photos/photosets/stamp.png';
        $opacity = "20";
        if (!file_exists($image)) {
            die("Image does not exist.");
        }
        // Set offset from bottom-right corner
        $w_offset = 0;
        $h_offset = 100;
        $extension = strtolower(substr($image, strrpos($image, ".") + 1));
        // Load image from file
        switch ($extension)
        {
            case 'jpg':
            $background = imagecreatefromjpeg($image);
            break;
            case 'jpeg':
            $background = imagecreatefromjpeg($image);
            break;
            case 'png':
            $background = imagecreatefrompng($image);
            break;
            case 'gif':
            $background = imagecreatefromgif($image);
            break;
            default:
            die("Image is of unsupported type.");
        }
        // Find base image size
        $swidth = imagesx($background);
        $sheight = imagesy($background);
        // Turn on alpha blending
        imagealphablending($background, true);
        // Create overlay image
        //$overlay = imagecreatefrompng($overlay);
        // Get the size of overlay
        $owidth = imagesx($overlay);
        $oheight = imagesy($overlay);
    
        $photo = imagecreatefromjpeg($image);
        $watermark = imagecreatefrompng($overlay);
                 // This is the key. Without ImageAlphaBlending on, the PNG won't render correctly.
        imagealphablending($photo, true);
                // Copy the watermark onto the master, $offset px from the bottom right corner.
        $offset = 10;
        imagecopy($photo, $watermark, imagesx($photo) - imagesx($watermark) - $offset, imagesy($photo) - imagesy($watermark) - $offset, 0, 0, imagesx($watermark), imagesy($watermark));
                // Output to the browser
        header("Content-Type: image/jpeg");
        imagejpeg($photo,$image);
        // Overlay watermark
        // Destroy the images
        imagedestroy($background);
        imagedestroy($overlay);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm capturing images using this code #pragma mark - image capture // Create and
I'm saving an uploaded image using this code: using (var fileStream = File.Create(savePath)) {
I'm using this code to create a rounded cornered image: CGContextBeginPath(context); CGRect rect =
I am using this code to create an image <?php // Set the content-type
Having this code: using (BinaryWriter writer = new BinaryWriter(File.Open(ProjectPath, FileMode.Create))) { //save something here
i have this function in my code and I'm using throw to create meaningful
i am trying to create slider movement graphics. The code explain better this. using
I am using this code to create a cookie with JQuery: $.cookie('MyCookieName', 'myValueHere'); It
I've been using this code to create my UIWindow UIMyWindow* win = [[UIMyWindow alloc]
I'm using this script to create a watermark on one of client's websites the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.