Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Imagecopy() Issue

Options
  • 20-02-2013 1:26am
    #1
    Registered Users Posts: 1,987 ✭✭✭


    I have the below code, there are no errors and the images is being created but not with the watermark image.

    Can anyone suggest what might be going on here?
    private function addWaterMark($fileIn) {
    	$stamp = imagecreatefrompng(WATERMARK_IMG);
    	$im = imagecreatefrompng($fileIn);
    
    	$marge_right = 10;
    	$marge_bottom = 10;
    	$sx = imagesx($stamp);
    	$sy = imagesy($stamp);
    
    	imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
    }
    


Comments

  • Closed Accounts Posts: 7,145 ✭✭✭DonkeyStyle \o/


    Code works for me.
    You don't seem to be doing anything with $im in that function though. Is it supposed to be locally scoped? It's pretty much just creating an image resource, then doing nothing with it. Needs to be written or returned.

    Here's the setup I used, the basic image operations are working fine.
    [PHP]<?php
    const WATERMARK_IMG = 'watermark.png';

    function addWaterMark($fileIn) {
    $stamp = imagecreatefrompng(WATERMARK_IMG);
    $im = imagecreatefrompng($fileIn);

    $marge_right = 10;
    $marge_bottom = 10;
    $sx = imagesx($stamp);
    $sy = imagesy($stamp);

    imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));

    imagejpeg($im, "test1.jpg", 100);
    }

    addWaterMark('filein.png');

    ?>[/PHP]


  • Registered Users Posts: 1,987 ✭✭✭Ziycon


    Nice one DonkeyStyle \o/, i had spent so long working looking at the code I failed to see the simplest of things. All working great now, thanks again.


Advertisement