I have created a simple PHP script to crop an image that has been previously uploaded to the server by the user and save it in another folder as some kind of a thumbnail.
$src_x = $_POST['left']; // Crop start x
$src_y = $_POST['top']; // Crop start y
$dst_w = $_POST['dim']; // Thumb width
$dst_h = $_POST['dim']; // Thumb height
$src_w = $_POST['dim']; // $src_x + $dst_w
$src_h = $_POST['dim']; // $src_y + $dst_h
$contact = $_POST['contact'];
$ratio = $_POST['ratio'];
$file_tmp = $_POST['file_tmp'];
$file_ext = strtolower(end(explode('.', $file_tmp)));
$img_info = getimagesize($file_tmp);
if ($file_ext == 'png') {
$src = imagecreatefrompng($file_tmp);
}
else if ($file_ext == 'jpeg' || $file_ext == 'jpg') {
$src = imagecreatefromjpeg($file_tmp);
}
else if ($file_ext == 'gif') {
$src = imagecreatefromgif($file_tmp);
}
$dst = imagecreatetruecolor(154, 154);
imagecopyresampled($dst, $src, 0, 0, $src_x * $ratio, $src_y * $ratio, 154, 154, $src_w * $ratio, $src_h * $ratio);
$img_name = $contact.'.png';
imagepng ($dst, '../images/invitados/'.$img_name);
The script works 100% fine with all jpeg / jpg / gif / png's EXCEPT for those images that have been imported by the user with iPhoto... Does anyone know what is going on??? I am going crazy 'cause I have no idea where the problem might be... The script doesn't even return a black image, so it doesn't even get to create the png...
Please help!
Many thanks