aarchaic Posted May 29, 2009 Share Posted May 29, 2009 I have a script that needs alteration. and since i've never worked with images and php this is a complete nightmare and not really sure how i should approach this. the code is as follows.... ( Found it here http://www.theopensurgery.com/29/php-upload-and-resize-image-script/ ) <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm"> <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button> </form> <?php if(isset($_POST['submit'])){ if (isset ($_FILES['new_image'])){ if(!file_exists("images")) { mkdir("images" , "0744") or die("Could not create images folder"); die("folder created!"); } $imagename = basename($_FILES['new_image']['name']); $source = $_FILES['new_image']['tmp_name']; $target = "images/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "images/" . $imagepath; //This is the new file you saving $file = "images/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 150; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "images/sml_" . $imagepath; //This is the new file you saving $file = "images/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $modwidth = 80; $diff = $width / $modwidth; $modheight = $height / $diff; $tn = imagecreatetruecolor($modwidth, $modheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "Large image: <img src='images/".$imagepath."'><br>"; echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; } } ?> this is what i need it to do... 1. large image of 500 pixels on the long side 2. medium image of 195 pixels on the long side 3. the thumb of 80 pixels on the long side. 4 work in an image size checker not larger than 2 meg... thanks for your help Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/ Share on other sites More sharing options...
jsschmitt Posted May 29, 2009 Share Posted May 29, 2009 Are you asking us for help, or to just do it for you? Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/#findComment-845129 Share on other sites More sharing options...
xcoderx Posted May 29, 2009 Share Posted May 29, 2009 Why not set height and width and stay happy? Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/#findComment-845144 Share on other sites More sharing options...
waynew Posted May 29, 2009 Share Posted May 29, 2009 And I'd like fries with that! Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/#findComment-845167 Share on other sites More sharing options...
aarchaic Posted May 30, 2009 Author Share Posted May 30, 2009 no i need help cause i really have no idea how to do it. i've been ok doing sessions cookies and database verification. but with images i have no experiences what so ever if some one can just give me some guide lines to how to it i'll give it a try. So if someone can just help me to get started i'll really appreciate it! Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/#findComment-845429 Share on other sites More sharing options...
aarchaic Posted June 1, 2009 Author Share Posted June 1, 2009 ok after a weekend of struggling i manage to work it out! here is the code... <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm"> <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> <button name="submit" type="submit" class="submitButton">Upload/Resize Image</button> </form> <?php if(isset($_POST['submit'])){ if (isset ($_FILES['new_image'])){ $imagename = basename($_FILES['new_image']['name']); $source = $_FILES['new_image']['tmp_name']; $target = "gfx/profilephotos/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "gfx/profilephotos/" . $imagepath; //This is the new file you saving $file = "gfx/profilephotos/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $largeimage=500; //sets the longest side $imgratio=$width/$height; //works out the image ratio and if its a portrait or landscape if ($imgratio>1){ //tests if it is a landscape $newwidth = $largeimage; //sets the longest side for landscape $newheight = $largeimage/$imgratio; //calculate the shortest side for landscape }else{ $newheight = $largeimage; //sets the longest side for Portrait $newwidth = $largeimage*$imgratio; //calculate the shortest side for Portrait } $tn = imagecreatetruecolor($newwidth, $newheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "gfx/profilephotos/med_" . $imagepath; //This is the new file you saving $file = "gfx/profilephotos/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $mediumimage=195; $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $mediumimage; $newheight = $mediumimage/$imgratio; }else{ $newheight = $mediumimage; $newwidth = $mediumimage*$imgratio; } $tn = imagecreatetruecolor($newwidth, $newheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; imagejpeg($tn, $save, 100) ; $save = "gfx/profilephotos/thumb_" . $imagepath; //This is the new file you saving $file = "gfx/profilephotos/" . $imagepath; //This is the original file list($width, $height) = getimagesize($file) ; $thumbimage=80; $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $thumbimage; $newheight = $thumbimage/$imgratio; }else{ $newheight = $thumbimage; $newwidth = $thumbimage*$imgratio; } $tn = imagecreatetruecolor($newwidth, $newheight) ; $image = imagecreatefromjpeg($file) ; imagecopyresampled($tn, $image, 0, 0, 0, 0, $newwidth, $newheight, $width, $height) ; imagejpeg($tn, $save, 100) ; echo "Large image: <img src='gfx/profilephotos/".$imagepath."'><br>"; echo "Medium: <img src='gfx/profilephotos/med_".$imagepath."'>"; echo "Thumbnail: <img src='gfx/profilephotos/thumb_".$imagepath."'>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/160174-solved-php-and-image-uploading/#findComment-846674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.