Arama butonu
Bu konudaki kullanıcılar: 1 misafir
0
Cevap
396
Tıklama
0
Öne Çıkarma
Php api resim upload boyutlandırma ve sıkıştırma
P
geçen yıl
Teğmen
Konu Sahibi

Merhaba, Aşağıdakii kod bloğu ile uzun zamandır çalışıyordum fakat dinamik bir yapıda değil. Örnek olarak 1920x1080 olan resmi orginal ve 2 tane thumb olmak üzere upload işlemi gerçekleştiriyorum. Fakat 400x250 ve 120x100 olarak dinamik olmayan bir yapı var. ve fotoğraflar yayılmış bir şekilde çıkıyor ve ek olarak telefon dikey olarak çekildiğinde 1080x1920 gibi terz çözünürlük oluyor onu da yatay olarak çeviriyor dolayısı ile her türlü yayılmış bozulmuş bir görüntü ortaya çıkıyor. Acaba bunun dinamik bir çözümü var mı?. Şimdiden teşekkür ediyorum.

<?php
function correctImageOrientation($filename)
{
$exif = exif_read_data($filename);
if ($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if ($orientation != 1) {
$img = imagecreatefromjpeg($filename);
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
if ($deg) {
$img = imagerotate($img, $deg, 0);
}
imagejpeg($img, $filename, 95);
}
}
}


function scale_image($image,$target,$target_width,$target_height)
{

if(!empty($image))
{
$source_image = null;


$exploded = explode('.',$image);
$ext = $exploded[count($exploded) - 1];

if (preg_match('/jpg|jpeg/i',$ext))
$source_image = imagecreatefromjpeg($image);
else if (preg_match('/png/i',$ext))
$source_image = imagecreatefrompng($image);
else if (preg_match('/gif/i',$ext))
$source_image = imagecreatefromgif($image);
else if (preg_match('/bmp/i',$ext))
$source_image = imagecreatefrombmp($image);



$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);



$dest_imagex = $target_width;
$dest_imagey = $target_height;



$image2 = imagecreatetruecolor($dest_imagex, $dest_imagey);
imagecopyresampled($image2, $source_image, 0, 0, 0, 0,
$dest_imagex, $dest_imagey, $source_imagex, $source_imagey);

imagejpeg($image2, $target, 65);
correctImageOrientation($target);
}
}



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));
scale_image($location.$name,
substr($location.$name,0,strrpos($location.$name, ".")) . "_120x100" . "." . $imageFileType, 640, 480);
scale_image($location.$name,substr($location.$name,0,strrpos($location.$name, ".")) . "_400x250" . "." . $imageFileType, 1920, 1080);
echo json_encode(['status' => 'ok']);
}else{
echo json_encode(['status' => 'fail']);
}
}else{
echo json_encode(['status' => 'errorfile']);
}
}


?>





DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.