allaboutthekick Posted January 11, 2007 Share Posted January 11, 2007 I would like to impliment a image resizer into this script that takes the image if it is bigger then 450w and resizes it. I dont know where or how to insert the code into this script, please suggest anything, thank you.[code]<?php // define the base image dir include("logincheck.php");$base_img_dir = "./img/";// define location of image conversion programs$img_conv_dir = "./bin/";// define database table containing image info$img_table = "images";// connect with databaseinclude('dbcon.php');// generate unique id for use in filename$uniq = uniqid("");// new file name$filename = $base_img_dir.$uniq;// move uploaded file to destinationmove_uploaded_file($HTTP_POST_FILES["file"]["tmp_name"], $filename);// retrieve image info$imginfo = getimagesize($filename);// handle image according to typeswitch ($imginfo[2]) { case 1: // gif // convert gif to png using shell command $command = $img_conv_dir."gif2png $filename"; exec($command); // remove original gif file and rename converted png unlink($filename); rename("$filename.png", $filename); // check png image by loading and saving the file // to prevent wrong uploaded files and errors $img = imagecreatefrompng($filename); imagepng($img, $filename); imagedestroy($img); // set image type to png $img_type = "PNG"; break;case 2: // jpeg // check jpeg image by loading and saving the file // to prevent wrong uploaded files and errors $img = imagecreatefromjpeg($filename); imagejpeg($img, $filename); imagedestroy($img); // set image type to jpeg $img_type = "JPG"; break; case 3: // png // check png image by loading and saving the file // to prevent wrong uploaded files and errors $img = imagecreatefrompng($filename); imagepng($img, $filename); imagedestroy($img); // set image type to png $img_type = "PNG"; break;case 4: // bmp // rename file to bmp rename($filename, "$filename.bmp"); // convert bmp to png using shell command $command = $img_conv_dir."bmptoppm $filename.bmp | ". $img_conv_dir."pnmtopng > $filename"; exec($command); // remove original bmp unlink("$filename.bmp"); // check png image by loading and saving the file // to prevent wrong uploaded files and errors $img = imagecreatefrompng($filename); imagepng($img, $filename); imagedestroy($img); // set image type to png $img_type = "PNG"; break; default: break;}// retrieve image file size$imgbytes = filesize($filename);// insert image into dbmysql_query("INSERT INTO $img_table (username, img_file, img_type, img_height, img_width, img_bytes, img_title, img_descr, img_alt) VALUES( '$username', '$uniq', '$img_type', ".$imginfo[1].", ".$imginfo[0].", $imgbytes, '".addslashes($HTTP_POST_VARS["title"])."', '". addslashes($HTTP_POST_VARS["descr"])."', '".addslashes($HTTP_POST_VARS["alt"])."');");// display some informationecho "Image uploaded.<br><img src=\"img/$uniq\"><br>". "URL: img/$uniq";?>[/code] Link to comment https://forums.phpfreaks.com/topic/33818-resizing-images-during-upload/ Share on other sites More sharing options...
allaboutthekick Posted January 11, 2007 Author Share Posted January 11, 2007 Extra:;I had read into some tutorials but all have pointed me towards this function:http://us3.php.net/manual/en/function.imagecopyresampled.phpIm not sure how to impliment that the script and maybe im going down the wrong path. Link to comment https://forums.phpfreaks.com/topic/33818-resizing-images-during-upload/#findComment-158704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.