Witam.
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) { if (!http://www.php.net/file_exists($path)) { http://www.php.net/mkdir($path, 0755, TRUE); } } 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; } } ?>
<?php require_once('functions.php'); if(http://www.php.net/isset($_FILES['image_file_input'])) { $output['status']=FALSE; http://www.php.net/set_time_limit(0); $allowedImageType = http://www.php.net/array("image/gif", "image/jpeg", "image/pjpeg", "image/png", "image/x-png" ); if ($_FILES['image_file_input']["error"] > 0) { $output['error']= "File Error"; } elseif (!http://www.php.net/in_array($_FILES['image_file_input']["type"], $allowedImageType)) { $output['error']= "Invalid image format"; } elseif (http://www.php.net/round($_FILES['image_file_input']["size"] / 1024) > 4096) { $output['error']= "Maximum file upload size is exceeded"; } else { $temp_path = $_FILES['image_file_input']['tmp_name']; $file = http://www.php.net/pathinfo($_FILES['image_file_input']['name']); $fileType = $file["extension"]; $fileName = http://www.php.net/rand(222, 888) . http://www.php.net/time() . ".$fileType"; $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; } } http://www.php.net/echo json_encode($output); } ?>
ja używam tego
https://www.php.net/manual/en/imagick.getimageorientation.php
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)