TeddyKiller Posted March 10, 2010 Share Posted March 10, 2010 This is basically a thumbnail image. How do I create it that.. whatever size image is being entered.. eg: $image how can I resize it to a suitable width and height. This may be making it smaller, or bigger though it wouldn't be much. The sizes I'd like it to be is 1"x1" (1 inch) I've seen image resizing scripts which.. basically you specify your image, and the images width and height. I can't do that, because the images are other users unless it automatically identifies it. Hope you can help. Link to comment https://forums.phpfreaks.com/topic/194833-image-resizing/ Share on other sites More sharing options...
TeddyKiller Posted March 11, 2010 Author Share Posted March 11, 2010 Probably very easy, but not sure. I have this.. <?php $num_printed = 0; $sql = mysql_query("SELECT Avatar FROM users WHERE Activated = '0' ORDER BY RAND() LIMIT 12"); if (mysql_num_rows($sql) > 0) { while ($item = mysql_fetch_array($sql)) { echo '<a href="#"><img src="'.$item['Avatar'].'" alt="user" border=0 /></a>'; $num_printed += 1; } } while( $num_printed < 12 ) { echo '<img src="profile/photos/default/default.jpg" alt="default" border=0 />'; $num_printed += 1; } ?> Though I'm wanting the images resized and and cropped. Please can you help, this is frustrating >.< Link to comment https://forums.phpfreaks.com/topic/194833-image-resizing/#findComment-1024502 Share on other sites More sharing options...
TeddyKiller Posted March 11, 2010 Author Share Posted March 11, 2010 Bump. Any ideas? I can't find absolutely anything. Link to comment https://forums.phpfreaks.com/topic/194833-image-resizing/#findComment-1024692 Share on other sites More sharing options...
TeddyKiller Posted March 11, 2010 Author Share Posted March 11, 2010 I have found this, made some slight changes to it. It uses the GD Graphics library which is installed along with the php library, though I'm looking to fix it in with the code I supplied above. I do not wish to include an upload form. In the other code I have image tags, these display the image. I need to resize the image without distorting it, and it may involve cropping. I'm not sure this tool does that, though here is what I've got. (Includes info.php which has phpinfo() <?php define ("MAX_SIZE","100"); define ("WIDTH","144"); define ("HEIGHT","144"); function make_thumb($img_name,$filename,$new_w,$new_h) { $ext=getExtension($img_name); if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); $old_x=imageSX($src_img); $old_y=imageSY($src_img); $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; } else { $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); imagedestroy($dst_img); imagedestroy($src_img); } function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=getimagesize($_FILES['image']['tmp_name']); $sizekb=filesize($_FILES['image']['tmp_name']); if ($sizekb > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $image_name=time().'.'.$extension; $newname="images/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; } else { $thumb_name='images/thumbs/thumb_'.$image_name; $thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT); }} }} if(isset($_POST['Submit']) && !$errors) { echo "<h1>Thumbnail created Successfully!</h1>"; echo '<img src="'.$thumb_name.'">'; } ?> <form name="newad" method="post" enctype="multipart/form-data" action=""> <table> <tr><td><input type="file" name="image" ></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> This uses alot of useless tools. With the code I supploed before, gets the pictures and displays them. Though i'm wanting to display them resized to 144 x 144 (1 x 1 inch) Link to comment https://forums.phpfreaks.com/topic/194833-image-resizing/#findComment-1024703 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.