Jump to content

Recommended Posts

Hi - I am trying to get a script to work which can watermark my images - I am working of this tutorial: -

 

http://www.trap17.com/index.php/watermark-image-simple-php-script_t36015.html

 

I have a file called watermark.php with the below code: -

<?php
    // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
    // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
    // where this script is named watermark.php
    // call this script with an image tag
    // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
    $imagesource =  $_GET['path'];
    $watermarkPath = $_GET['watermark'];
    $filetype = substr($imagesource,strlen($imagesource)-4,4);
    $filetype = strtolower($filetype);
    $watermarkType = substr($watermarkPath,strlen($watermarkPath)-4,4);
    $watermarkType = strtolower($watermarkType);

    if($filetype == ".gif")  
        $image = @imagecreatefromgif($imagesource);
    else  
        if($filetype == ".jpg" || $filetype == "jpeg")  
            $image = @imagecreatefromjpeg($imagesource);
        else
            if($filetype == ".png")  
                $image = @imagecreatefrompng($imagesource);
            else
                die();  
    
    if(!$image)
        die();
    
    if($watermarkType == ".gif")
        $watermark = @imagecreatefromgif($watermarkPath);
    else
        if($watermarkType == ".png")
            $watermark = @imagecreatefrompng($watermarkPath);
        else
            die();
        
    if(!$watermark)
        die();
        
    $imagewidth = imagesx($image);
    $imageheight = imagesy($image);  
    $watermarkwidth =  imagesx($watermark);
    $watermarkheight =  imagesy($watermark);
    $startwidth = (($imagewidth - $watermarkwidth)/2);
    $startheight = (($imageheight - $watermarkheight)/2);
    imagecopy($image, $watermark,  $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
    imagejpeg($image);
    imagedestroy($image);
    imagedestroy($watermark);
?>

 

Within the directory I have - watermark.php, index.php, watermark.gif & test.jpg

 

index.php simply contains: -

 

<?
header("Content-type: image/jpeg");
?>
<img src="watermark.php?path=test.jpg&watermark=watermark.gif" />

 

All it seems to display is the page url ... no image - any ideas why??

Link to comment
https://forums.phpfreaks.com/topic/132286-simple-php-watermark-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.