I've been experimenting with the imagecopyresampled function in PHP.
It has this example code:
<?php
// The file
$filename = 'test.jpg';
// Set a maximum height and width
$width = 200;
$height = 200;
// Content type
header('Content-type: image/jpeg');
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);
$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($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// Output
imagejpeg($image_p, null, 100);
?>
However, I've adapted it to use a file upload method and what I'm finding is that if a file is too big, e.g. a 4272 x 2848 and weighing in around 4.5MB I get nothing back from the imagecreatefromjpeg. The file uploads fine (I can grab the content and output that directly) so it's something to do with that function.
The problem is that I can't work out how to tell at what point a file will be too big so I can exit gracefully and error out rather than just leaving the person with no output.
Any ideas?
Cheers