Posiadam funkcje odpowiedzialne za wgranie i resize obrazka w locie.
Problem zaczyna się, gdy chcę skalować różnej szerokości obrazki.
Tutaj mam wklepany rozmiar dla zdjęć pionowych. Jak zrobić, aby w jakiś sposób wykrywać czy zdjęcie jest poziome i pionowe i wtedy dopasować konkretną proporcję rozmiaru?
Wszystko fajnie działa, gdy obrazek jest pionowy. Przy poziomym zaczynają się schody.
Jak to rozwiązać?
Poniżej fragment kodu
functions.php:
<?php function createFolder($path) { } } function createThumbnail($sourcePath, $targetPath, $file_type, $thumbWidth, $thumbHeight){ $source = imagecreatefromjpeg($sourcePath); $width = imagesx($source); $height = imagesy($source); $tnumbImage = imagecreatetruecolor($thumbWidth, $thumbHeight); imagecopyresampled($tnumbImage, $source, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $width, $height); if (imagejpeg($tnumbImage, $targetPath, 90)) { imagedestroy($tnumbImage); imagedestroy($source); return TRUE; } else { return FALSE; } } ?>
image_upload_submit.php:
<?php require_once('functions.php'); { $output['status']=FALSE; if ($_FILES['image_file_input']["error"] > 0) { $output['error']= "File Error"; } $output['error']= "Invalid image format"; } $output['error']= "Maximum file upload size is exceeded"; } else { $temp_path = $_FILES['image_file_input']['tmp_name']; $fileType = $file["extension"]; $small_thumbnail_path = "uploads/small/"; createFolder($small_thumbnail_path); $small_thumbnail = $small_thumbnail_path . $fileName; $medium_thumbnail_path = "uploads/medium/"; createFolder($medium_thumbnail_path); $medium_thumbnail = $medium_thumbnail_path . $fileName; $large_thumbnail_path = "uploads/large/"; createFolder($large_thumbnail_path); $large_thumbnail = $large_thumbnail_path . $fileName; $thumb1 = createThumbnail ($temp_path, $small_thumbnail,$fileType, 160, 193); $thumb2 = createThumbnail($temp_path, $medium_thumbnail, $fileType, 360, 547); $thumb3 = createThumbnail($temp_path, $large_thumbnail,$fileType, 460, 647); if($thumb1 && $thumb2 && $thumb3) { $output['status']=TRUE; $output['small']= $small_thumbnail; $output['medium']= $medium_thumbnail; $output['large']= $large_thumbnail; } } } ?>