phpretard Posted June 3, 2008 Share Posted June 3, 2008 This is the script I'm using to upload images. Is there something I can add to resize the image proportionaly so that is fits on the page where it is later echoed? or Can I set a max width / height when displayed? function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['uploaded']['name']) ; $ran = rand (111111, 999999). $company ; $ran2 = $ran."."; $target = "pages/secure/partners/img/"; $target = $target . $ran2.$ext; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { mysql_query("INSERT INTO partners (id, company, url, uploaded, blurb ) VALUES ('', '$company', '$url', '$target', '$blurb')"); $success="<center><font color=red size=2>Upload Successful!</font><br><br></center>"; } Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/ Share on other sites More sharing options...
Loldongs Posted June 3, 2008 Share Posted June 3, 2008 Use the GD PHP Extension here is a simple script to resize an image <?php // Load image $image = open_image('flower.jpg'); if ($image === false) { die ('Unable to open image'); } // Get original width and height $width = imagesx($image); $height = imagesy($image); // New width and height $new_width = 150; $new_height = 100; // Resample $image_resized = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Display resized image header('Content-type: image/jpeg'); imagejpeg($image_resized); die(); ?> Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556347 Share on other sites More sharing options...
phpretard Posted June 3, 2008 Author Share Posted June 3, 2008 Can $new_width = 150; $new_height = 100; be a percentage? Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556351 Share on other sites More sharing options...
Wolphie Posted June 3, 2008 Share Posted June 3, 2008 Yes, probably. However, i'm not too sure. Theres only one way to find out. Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556352 Share on other sites More sharing options...
ibolui Posted June 3, 2008 Share Posted June 3, 2008 $new_width = $percent * $width; $new_height = $percent * $height; something like this?? Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556353 Share on other sites More sharing options...
phpretard Posted June 3, 2008 Author Share Posted June 3, 2008 I am really trying to keep this as simple as possible. I have many different size images in different formats in a file and just want to display them with a max height and width. I tried CSS well... IE is IE (works great in FF). Is there a simple way? Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556383 Share on other sites More sharing options...
samshel Posted June 3, 2008 Share Posted June 3, 2008 Give width as fixed instead of percentage in CSS. Do not specify height, it will adjust automatically. However i would advice using the script given by Loldongs. This will save you upload time, disk space and page rendering time. Link to comment https://forums.phpfreaks.com/topic/108506-image-upload/#findComment-556394 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.