All pastes #609098 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-08 17:49 UTC
rendered paste body
                                         // Set a maximum height and width
                                                                 $width = 150;
                                                                 $height = 150;


                                                                 // Get new dimensions
                                                                 list($width_orig, $height_orig) = getimagesize($file_destination);

                                                                 $ratio_orig = $width_orig/$height_orig;

                                                                 if ($width/$height > $ratio_orig) {
                                                                   $width = $height*$ratio_orig;
                                                                 } else {
                                                                   $height = $width/$ratio_orig;
                                                                 }

                                                                 // Resample
                                                                 $image_p = imagecreatetruecolor($width, $height);
                                                                 $image = imagecreatefromjpeg($file_destination);
                                                                 imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

                                                                 // Output
                                                                 imagejpeg($image_p, $thumbnail_image, 100);