Jump to content

Convert uploaded image to jpg and add logo


phillips321

Recommended Posts

Hi guys,

 

I have got my script working so that only GIF, PNG, BMP and JPG files can be uploaded.

 

It then saves these images to the "uploads" directory.

 

What i would like to do is automatically convert these images to jpg and also add a small logo onto the image before saving it.

 

I have heard of imagemagic but i dont really know how to use it.

 

Anyone know of any tutorials or code i can have a look through to help me?

 

Is this going to be difficult to do?

 

P.s. My existing upload code is below

<?php
$path= "uploads/".$HTTP_POST_FILES['ufile']['name'];
$quit=0;
$size= $HTTP_POST_FILES['ufile']['size'];
$type= $HTTP_POST_FILES['ufile']['type'];

if($size > 350000)
{
        echo "Your file is too large.<br>";
        $quit=1;
}

if(($type == "image/jpeg") || ($type == "image/gif") || ($type == "image/png") || ($type == "image/bmp"))
{
        if(!($quit==1))
        {
                if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
                {
                        echo "Successful<BR/>";
                        echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>";
                        echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
                        echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
                        echo "Image Location: <A href=".$path.">http://forumpix.getmyip.com/".$path."</A><BR/>";
                        echo "<img src=\"$path\">";
                }
        }
        else
        {
        echo "There was an error.<br>";
        }
}
else
{
        echo "You may only upload JPG, BMP, PNG or GIF images.<br>";
        $quit=1;
}




?>

Link to comment
Share on other sites

To convert the file types, use imagecreatefromgif, imagecreatefrompng  and imagecreatefromwbmp

 

A week or so ago, someone posted code to add a watermark.

 

Found it....

<?php  

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

$original_image = "image.jpg";

$watermark = imagecreatefrompng('watermark.png');  
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatetruecolor($watermark_width, $watermark_height);  
$image = imagecreatefromjpeg($original_image);  
$size = getimagesize($original_image);  
$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.