Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    image resize and watermark / 2 scripts in one

    Hello everyone,

    I need a little help. I'm not a PHP expert, I think this one is an easy one but still... I cannot solve it :P

    I have 2 scripts, one for Image resizing and another one for watermark. I need to merge these 2 scripts in one. First to do the image resizing and then apply the watermark, and post the resulted image. I don/t know why it doesnt work to use for the watermark script the result of the first script....

    I will attach the two scripts. Thanks a lot for you help.


    DR.
    Attached Files Attached Files

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    this should work, but i haven't tested it;

    Code:
    header('content-type: image/jpeg');
    $img = $_GET['img'];
    $watermark = imagecreatefrompng('watermark.png');
    
    $watermark_width = imagesx($watermark);
    $watermark_height = imagesy($watermark);
    $image = imagecreatetruecolor($watermark_width, $watermark_height);
    $image = imagecreatefromjpeg("$img");
    $size = getimagesize("$img");
    $dest_x = $size[0]/2 - $watermark_width/2 ;
    $dest_y = $size[1]/2 - $watermark_height/2;
    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
    
    imagecopyresized($image, $watermark, 0, 0, 0, 0, imagesx($image), imagesy($image), $size[0], $size[1]);
    
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);

  • #3
    New to the CF scene
    Join Date
    Sep 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks angst,

    In your code I cannot figure how I can send the size of the resized image that I want. Anyway, I figured myself how to merge the two scripts and it-s solved now by adding the watermark script inside the resizing script and the right variable to use was $src

    $img = $_GET['img']; / $img = $src;


    Thanks for your time.
    DR.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •