Jump to content

php gd


dezkit

Recommended Posts

i was googling "php watermark" and i stumbled upon this code.... but i can't get it to work... why?

 

 

index.php


<?php
$image = $HTTP_GET_VARS['image']; // Useful if using in an img tag to call images
$image = str_replace(array("/", ".."), "", $image); // Prevent abuse
$overlay = 'http://www.chestysoft.com/images/watermark.png';
$dir = '../hresources/';
if ($image == NULL) {
    $image = 'http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg';
}
if (!file_exists($dir . $image)) {
    die("Image does not exist.");
}
$w_offset = 0;
$h_offset = 0;
$extension = strtolower(substr($image, strrpos($image, ".") + 1));
switch ($extension)
{
    case 'jpg':
        $background = imagecreatefromjpeg($dir . $image);
        break;
    case 'jpeg':
        $background = imagecreatefromjpeg($dir . $image);
        break;
    case 'png':
        $background = imagecreatefrompng($dir . $image);
        break;
    case 'gif':
        $background = imagecreatefromgif($dir . $image);
        break;
    default:
        die("Image is of unsupported type.");
}
$swidth = imagesx($background);
$sheight = imagesy($background);
imagealphablending($background, true);
$overlay = imagecreatefrompng($dir . $overlay);
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);
imagecopy($background, $overlay, $swidth - $owidth - $w_offset, $sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight);
header("Content-type: image/jpeg");
header("Content-Disposition: filename=" . $image);
imagejpeg($background);
imagedestroy($background);
imagedestroy($overlay);

?> 

 

i go into my index.php and it says Image doesn't exist.

Link to comment
Share on other sites

<?php

$overlay = 'http://www.chestysoft.com/images/watermark.png';
$dir = '../hresources/';
if ($image == NULL) {
    $image = 'http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg';
}
if (!file_exists($dir . $image)) {
    die("Image does not exist.");
}

?>

 

If $image is null its going to try and find an image called "../hresources/http://www.uscg.mil/mlcpac/ischon/mwr/images/club14/club.jpg"

 

Which doesnt really make sense.

 

Make sure the image you are referencing actually exists on your server and that you are referring to it correctly.

Link to comment
Share on other sites

what about this code, i don't understand, i put it in my index.php, what do i do now?

 

<?php 

 

header('content-type: image/jpeg'); 

 

$watermark = imagecreatefrompng('watermark.png'); 

$watermark_width = imagesx($watermark); 

$watermark_height = imagesy($watermark); 

$image = imagecreatetruecolor($watermark_width, $watermark_height); 

$image = imagecreatefromjpeg($_GET['src']); 

$size = getimagesize($_GET['src']); 

$dest_x = $size[0] - $watermark_width - 5; 

$dest_y = $size[1] - $watermark_height - 5; 

imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100); 

imagejpeg($image); 

imagedestroy($image); 

imagedestroy($watermark); 

 

?>

Link to comment
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.