Hello, I have a dating site. When members upload their images, how do I resize the images to be 300px width and let the height automatically? some images are large so they load too slow. Can you please help? Thanks, Jenny. p.s. Here is the upload image code block: <input name = "image_<? echo $i;?>" type = "text" id="image_<? echo $i;?>" value="<? echo $image[$i];?>" size="20" readOnly > <input type=BUTTON name=btn_name<? echo $i;?> value="Upload" onClick=attachment('image_<? echo $i;?>')> Code (markup):
Make a seperate php file that will resize the image... <? $file = "asdf.jpg"; $w2 = "640"; // New dimensions $h2 = "480"; header("Content-Type: image/png"); $dot = explode ( '.', $file ); $dot = array_reverse ( $dot ); switch($dot[0]){ case 'jpg':$image = imagecreatefromjpeg($file);break; case 'gif':$image = imagecreatefromgif($file);break; case 'png':$image = imagecreatefrompng($file);break; } list($w, $h) = getimagesize($file); $resized = imagecreatetruecolor($w2, $h2); imagecopyresized($resized, $image, 0, 0, 0, 0, $w2, $h2, $w, $h); imagedestroy($image); imagepng($resized); imagedestroy($resized); ?> PHP: Of course, your server will need to have gd and image functions installed.
Thanks for your help. What does this file asdf.jpg mean? is this a makeup file I choose any? The script you showed above will resize all images after members upload their images on my site, right? Thanks.
I try to resize images for a folder that have more than 200 images. This script does one by one which is not what I am looking for. If one by one, I can use Photoshop to resize each image. Thanks.
I've been using an image resizing function for a while, and it works well. Technically, it saves the picture as whatever dimensions it's uploaded to, but it limits the dimensions in which it is viewed on. Hope this helps. function resizeImage($image,$target) { // Get the current image size $image = getimagesize($image); // Get percentage if ($image[0] > $image[1]) { $percent = $target / $image[0]; } else { $percent = $target / $image[1]; } // Get new width and height $w = round($image[0] * $percent); $h = round($image[1] * $percent); // Return as an html $htmlWH = "width=\"" . $w . "\" height=\"" . $h . "\""; return $htmlWH; } PHP: And this is an example of how you would use it: resizeImage($row['image'], 200) PHP:
I can write a script to run through your images folder and convert them all to a certain size for a fee. After that, you may consider embedding the resize program into your upload script. It would be best to read the image into a variable from the temporary upload directory, resize it, and then save it to the final directory using imagejpeg();.