phillips321 Posted September 23, 2007 Share Posted September 23, 2007 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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70347-convert-uploaded-image-to-jpg-and-add-logo/ Share on other sites More sharing options...
phillips321 Posted September 23, 2007 Author Share Posted September 23, 2007 just to note i already have GD installed on the server so if i could use that it would be handy. I've been looking at this site but i'm still confused http://uk3.php.net/gd Quote Link to comment https://forums.phpfreaks.com/topic/70347-convert-uploaded-image-to-jpg-and-add-logo/#findComment-353368 Share on other sites More sharing options...
tippy_102 Posted September 23, 2007 Share Posted September 23, 2007 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/70347-convert-uploaded-image-to-jpg-and-add-logo/#findComment-353489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.