https://github.com/claviska/SimpleImage
basit ve kullanımı kolay, orientation yapılabilen ve istenilen boyutlarda çıktı verebilen bi sınıf.
bestFit() fonksiyonunu kullanırsanız resim bozulmadan en uygun şekilde belirlediğiniz boyut için resmi eğip bükmeden boyutlandırır.
Öncelikle çok teşekkür ederim. Kodumu aşağıda ki gibi güncelledim, oriantation ve mb olarak boyut küçültmesini yaptı. Fakat koddaki aşağıdaki kod da görüldüğü gibi _480x360 ve _1024x768 boyutlarında iki tane resim boyutlandırmasını yaptırmaya çalışıyorum. isim olarak ikisi de yükleniyor fakat boyutları ve çözünürlüklerini aynı yapıyor.
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('claviska/SimpleImage.php');
if(isset($_FILES["uploaded_file"]["name"])) {
$name = $_FILES["uploaded_file"]["name"];
$tmp_name = $_FILES["uploaded_file"]["tmp_name"];
$error = $_FILES["uploaded_file"]["error"];
if(!empty($name)){
$location = '../appapibizifarkedin/resimler/';
if(!is_dir($location)) {
mkdir($location);
}
if(move_uploaded_file($tmp_name, $location.$name)){
$imageFileType = strtolower(pathinfo($location.$name, PATHINFO_EXTENSION));
$simpleImage = new \claviska\SimpleImage();
$simpleImage->fromFile($location.$name)
->autoOrient()
->bestFit(480, 360, ['aspectRatio' => true])
->toFile(substr($location.$name, 0, strrpos($location.$name, ".")) . "_480x360." . $imageFileType)
->bestFit(1024, 768, ['aspectRatio' => true])
->toFile(substr($location.$name, 0, strrpos($location.$name, ".")) . "_1024x768." . $imageFileType);
echo json_encode(['status' => 'ok']);
exit;
} else {
echo json_encode(['status' => 'fail']);
exit;
}
} else {
echo json_encode(['status' => 'errorfile']);
exit;
}
}
?>Edit: Aşağıdaki kodu çalışanla güncelliyorum. Tekrardan teşekkür ederim bu kütüphaneyi önerdiğiniz için. Çözünürlükleri ayrı ayrı değişlenle yaptığımda çalıştı. Çalışan kod aşağıdadır. İşine yarayan çıkar diye ekledim. (Not: PHP 8 altında hata alınıyor. En az 8 olması gerek)
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once('claviska/SimpleImage.php');
if(isset($_FILES["uploaded_file"]["name"])) {
$name = $_FILES["uploaded_file"]["name"];
$tmp_name = $_FILES["uploaded_file"]["tmp_name"];
$error = $_FILES["uploaded_file"]["error"];
if(!empty($name)){
$location = '../appapibizifarkedin/resimler/';
if(!is_dir($location)) {
mkdir($location);
}
if(move_uploaded_file($tmp_name, $location.$name)){
$imageFileType = strtolower(pathinfo($location.$name, PATHINFO_EXTENSION));
$simpleImage = new \claviska\SimpleImage();
$simpleImage->fromFile($location.$name)
->autoOrient()
->bestFit(640, 480, ['aspectRatio' => true])
->toFile(substr($location.$name, 0, strrpos($location.$name, ".")) . "_400x250." . $imageFileType);
$simpleImage = new \claviska\SimpleImage();
$simpleImage->fromFile($location.$name)
->autoOrient()
->bestFit(480, 360, ['aspectRatio' => true])
->toFile(substr($location.$name, 0, strrpos($location.$name, ".")) . "_120x100." . $imageFileType);
echo json_encode(['status' => 'ok']);
exit;
} else {
echo json_encode(['status' => 'fail']);
exit;
}
} else {
echo json_encode(['status' => 'errorfile']);
exit;
}
}
?>