/ Published in: PHP

Tweaked from the icant.co.uk thumbnail generator
Expand |
Embed | Plain Text
<?php ## # # $name = full path to original source # $filename = full path to thumbnail # $new_w thumbnail width # $new_h thumbnail height # $debug echo a few diagnostics # ## function createthumb($name,$filename,$new_w=500,$new_h=373,$debug=false) { $results = ""; $results = "file extension = $system <br>"; $old_x=imageSX($src_img); $old_y=imageSY($src_img); $results .= "image size = $old_x x $old_y <br>"; if($old_x > $old_y) { $thumb_h = $new_h; $ratio = $new_h / $old_y; $thumb_w = ($old_x * $ratio); } if($old_x < $old_y) { $thumb_w = $new_w; $ratio = $new_w / $old_x; $thumb_h = ($old_y * $ratio); } if($old_x == $old_y) { $thumb_w = $new_w; $thumb_h = $new_h; } if($new_h < $thumb_h) { } else { $yloc = 0; } $results .= "output size = $thumb_w x $thumb_h <br> y offset = $yloc <br>"; $dst_img = ImageCreateTrueColor($new_w,$new_h); imagecopyresampled($dst_img,$src_img,0,0,0,$yloc,$thumb_w,$thumb_h,$old_x,$old_y); imagepng($dst_img,$filename); } else { imagejpeg($dst_img,$filename); } imagedestroy($dst_img); imagedestroy($src_img); return "Resized the image successfully!"; } ?>
You need to login to post a comment.