load($source_path); // next will resize so that the largest length is 300px - height or width //$im->resize(100, 50); $im->scaleByX($new_width); // next is a subclass call that calls the above with a set size. //$im->addText(array('text' => 'Annotated')); $im->display(); //$im->save($cache_file); die; $srcimg = ImageCreateFromJPEG($source_path); $old_x = imageSX($srcimg); $old_y = imageSY($srcimg); if ($old_x > $old_y) { $thumb_w = $new_width; $thumb_h = $old_y*($new_height/$old_x); } if ($old_x < $old_y) { $thumb_w = $old_x*($new_width/$old_y); $thumb_h = $new_height; } if ($old_x == $old_y) { $thumb_w = $new_width; $thumb_h = $new_height; } $destimg = imagecreatetruecolor($thumb_w,$thumb_h); imagecopyresized($destimg,$srcimg,0,0,0,0,$thumb_w,$thumb_h,ImageSX($srcimg),ImageSY($srcimg)); header("Content-type: image/jpeg"); //Header("Content-type: image/png"); ImageJPEG($destimg); } ?>