Jump to content

Image resize and watermarking On The Fly.


lopes_andre

Recommended Posts

Hi all,

 

I'am trying to resize an image and watermarking in the same proccess using CodeIgniter, but without success, I'am able to do only one operation at the same time.

 

Because I'am not able to do it using CodeIgniter Image_lib... my question is:

 

It is possible to resize an image and watermarking On The Fly using GD library? If yes, do you know some examples?

 

 

Best Regards,

 

Here is some code I wrote a while back for the same feature.

 

Works like this:

 

script.php?src=yourimage.jpg

 

Then you can put that in an img html tag:

 

<img src="script.php?src=youimage.jpg"  />

 

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

$watermark = imagecreatefromgif('watermark.gif'); //your watermark image. 
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg("imageuploads/".$_GET['src']);   // change to location of file. $get[src] is just the file name and extensions. e.g  filename.jpg 
$size = getimagesize("imageuploads/".$_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);  
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.