$source_height) { // Landscape image, width is 1024 $target_width=1024; $target_height=floor(($source_height/$source_width)*1024); } else { // Portrait (or square), height is 1024 $target_width=floor(($source_width/$source_height)*1024); $target_height=1024; } $png = imagecreatetruecolor($target_width, $target_height); imagecopyresampled($png, $image, 0, 0, 0, 0, $target_width, $target_height, $source_width, $source_height); header('Content-Type: image/png'); imagepng($png);