supanoob Posted September 20, 2006 Share Posted September 20, 2006 The Below code is what i am using to upload and resize images. now i have tried uploading 2 images one of them was 300 x 300 and another was 200 x 200 and neither uploaded it cam up with an error saying it was divsion by 0 :S can anyone see why?[code]$uploaddir = "/public_html/player_images/"; $pext = getFileExtension($imgfile_name); $pext = strtolower($pext); if (($pext != "jpg") && ($pext != "jpeg")) { print "<h1>ERROR</h1>Image Extension Unknown.<br>"; print "<p>Please upload only a JPEG image with the extension .jpg or .jpeg ONLY<br><br>"; print "The file you uploaded had the following extension: $pext</p>\n"; unlink($imgfile); exit(); } $imgsize = GetImageSize($imgfile); if (($imgsize[0] > 200) || ($imgsize[1] > 200)) { $tmpimg = tempnam("/tmp", "MKUP"); 1. decompress jpeg image to pnm file (a raw image type) 2. scale pnm image 3. compress pnm file to jpeg image system("djpeg $imgfile >$tmpimg"); system("pnmscale -xy 200 200 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile"); unlink($tmpimg); } $final_filename = str_replace(" ", "_", $imgfile_name); $newfile = $uploaddir/$final_filename; if (is_uploaded_file($imgfile)) { if (!copy($imgfile,"$newfile")) { print "Error Uploading File."; exit(); } } unlink($imgfile); echo "<img src=\"/public_html/player_images/$final_filename\">";[/code] Quote Link to comment Share on other sites More sharing options...
redarrow Posted September 20, 2006 Share Posted September 20, 2006 heres an example how to resize an image ok.gd must be enabled in the php.ini [code]<?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 imageheader('Content-type: image/jpeg');imagejpeg($image_resized);die();?>[/code] Quote Link to comment Share on other sites More sharing options...
supanoob Posted September 20, 2006 Author Share Posted September 20, 2006 so where in my code would that go? the code i used was an example off of a website along with the functions off of php.net Quote Link to comment 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.