• 30-06-2014, 11:01:07
    #1
    Merhaba,

    verot.net upload sınıfını kullanıyorum. Yüklenen resmin 3 farklı halini kaydetmeye çalışıyorum. 1.si yüklendiği hali, 2.si gri hali, 3.sü belirlediğim boyutlardaki hali. Orjinal ve gri halini yükleyebiliyorum bir problem yok fakar thumbnail olayına girdiğim zaman herhangi bir sonuç alamıyorum. Nerede hata yapıyorum?

      $default='';
      $other='';
      $files = array(); 
       foreach ($_FILES['images'] as $k => $l) { 
         foreach ($l as $i => $v) { 
             if (!array_key_exists($i, $files)) 
                 $files[$i] = array(); 
             $files[$i][$k] = $v; 
         } 
       } 
      $uploaded = array();
       foreach ($files as $file):
         $handle = new Upload($file); 
         if ($handle->uploaded):
            $this_upload = array();
            $handle->file_new_name_body 	= substr(base64_encode(uniqid(true)), 0, 20);
            $handle->Process(realpath("../")."/uploads/products/default/");
            $this_upload[] = $handle->file_dst_name;
            $default = $default. $handle->file_dst_name . ',';
            //Generate greyscale
            $handle->image_greyscale       	= true;
    		$handle->file_new_name_body    	= substr(base64_encode(uniqid(true)), 0, 20);
            $handle->Process(realpath("../")."/uploads/products/other/");
    		$other = $other. $handle->file_dst_name . ',';
    		//Generate thumbnail
            $handle->image_resize = true;
    		$handle->file_new_name_body    	= substr(base64_encode(uniqid(true)), 0, 20);
            $handle->image_x = 120;
            $handle->image_y = true;
            $handle->Process( realpath("../")."uploads/products/thumb/" );
         endif;
       endforeach;
  • 04-07-2014, 11:05:29
    #2
    Bu konuda bir bilgisi olan yok mu?
  • 04-07-2014, 12:28:17
    #3
    Üyeliği durduruldu
    loc adlı üyeden alıntı: mesajı görüntüle
    Bu konuda bir bilgisi olan yok mu?
    loc adlı üyeden alıntı: mesajı görüntüle
    Bu konuda bir bilgisi olan yok mu?
    https://www.r10.net/php/1242899-php-d...islemleri.html


    Konuyu İnceleyebilirsin Hocam

    Güzel Bir Anlatım Yapmıştım

    Curl İle Çekilen Resimler İçin yapmıştım Anlatımı Fakat Aynı Şekilde Resim Boyutlandırma Alanlarını Resmin ilk halini kaydettigin kodlara ekleme yapıp kullnabilirsin zaten heryerde acıklama yaptım konuda
  • 04-07-2014, 12:29:05
    #4
    $default='';
    $other='';
    $files = array(); 
     foreach ($_FILES['images'] as $k => $l) { 
       foreach ($l as $i => $v) { 
           if (!array_key_exists($i, $files)) 
               $files[$i] = array(); 
           $files[$i][$k] = $v; 
       } 
     } 
    $uploaded = array();
     foreach ($files as $file):
       $handle = new Upload($file); 
       if ($handle->uploaded):
          $this_upload = array();
          $handle->file_new_name_body    = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->Process(realpath("../")."/uploads/products/default/");
          $this_upload[] = $handle->file_dst_name;
          $default = $default. $handle->file_dst_name . ',';
          //Generate greyscale
          $handle->image_greyscale          = true;
        $handle->file_new_name_body      = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->Process(realpath("../")."/uploads/products/other/");
        $other = $other. $handle->file_dst_name . ',';
        //Generate thumbnail
          $handle->image_resize = true;
        $handle->file_new_name_body      = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->image_ratio_crop = true;
          $handle->image_x = 120;
          $handle->image_ratio_y = true;
          $handle->Process( realpath("../")."uploads/products/thumb/" );
       endif;
     endforeach;
    şu şekilde dener misiniz?
  • 04-07-2014, 13:14:25
    #5
    msgr adlı üyeden alıntı: mesajı görüntüle
    $default='';
    $other='';
    $files = array(); 
     foreach ($_FILES['images'] as $k => $l) { 
       foreach ($l as $i => $v) { 
           if (!array_key_exists($i, $files)) 
               $files[$i] = array(); 
           $files[$i][$k] = $v; 
       } 
     } 
    $uploaded = array();
     foreach ($files as $file):
       $handle = new Upload($file); 
       if ($handle->uploaded):
          $this_upload = array();
          $handle->file_new_name_body    = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->Process(realpath("../")."/uploads/products/default/");
          $this_upload[] = $handle->file_dst_name;
          $default = $default. $handle->file_dst_name . ',';
          //Generate greyscale
          $handle->image_greyscale          = true;
        $handle->file_new_name_body      = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->Process(realpath("../")."/uploads/products/other/");
        $other = $other. $handle->file_dst_name . ',';
        //Generate thumbnail
          $handle->image_resize = true;
        $handle->file_new_name_body      = substr(base64_encode(uniqid(true)), 0, 20);
          $handle->image_ratio_crop = true;
          $handle->image_x = 120;
          $handle->image_ratio_y = true;
          $handle->Process( realpath("../")."uploads/products/thumb/" );
       endif;
     endforeach;
    şu şekilde dener misiniz?
    malesef işe yaramadı

    --R10.NET; Flood Engellendi -->-> Yeni yazılan mesaj 13:14:25 -->-> Daha önceki mesaj 13:13:11 --

    Sample adlı üyeden alıntı: mesajı görüntüle
    https://www.r10.net/php/1242899-php-d...islemleri.html


    Konuyu İnceleyebilirsin Hocam

    Güzel Bir Anlatım Yapmıştım

    Curl İle Çekilen Resimler İçin yapmıştım Anlatımı Fakat Aynı Şekilde Resim Boyutlandırma Alanlarını Resmin ilk halini kaydettigin kodlara ekleme yapıp kullnabilirsin zaten heryerde acıklama yaptım konuda
    Benim anlamadığım ilk iki türde bir problem yokken neden thumbnail almaya çalışırken upload etmiyor. Kafam orada takıldı. Kendi kodlarıma baktığım zaman bir problem göremiyorum.
  • 04-07-2014, 13:55:51
    #6
    bunu boyutlandir.php olarak kaydedin;

    <?php
    class resize
    {
    private $image;
    private $width;
    private $height;
    private $imageResized;
    
    function __construct($fileName)
    {
    $this->image = $this->openImage($fileName);
    $this->width = imagesx($this->image);
    $this->height = imagesy($this->image);
    }
    
    private function openImage($file)
    {
    $extension = strtolower(strrchr($file, '.'));
    switch($extension)
    {
    case '.jpg':
    case '.jpeg':
    $img = @imagecreatefromjpeg($file);
    break;
    case '.gif':
    $img = @imagecreatefromgif($file);
    break;
    case '.png':
    $img = @imagecreatefrompng($file);
    break;
    default:
    $img = false;
    break;
    }
    return $img;
    }
    
    public function resizeImage($newWidth, $newHeight, $option="auto")
    {
    $optionArray = $this->getDimensions($newWidth, $newHeight, $option);
    $optimalWidth = $optionArray['optimalWidth'];
    $optimalHeight = $optionArray['optimalHeight'];
    
    $this->imageResized = imagecreatetruecolor($optimalWidth, $optimalHeight);
    imagecopyresampled($this->imageResized, $this->image, 0, 0, 0, 0, $optimalWidth, $optimalHeight, $this->width, $this->height);
    
    if ($option == 'crop') {
    $this->crop($optimalWidth, $optimalHeight, $newWidth, $newHeight);
    }
    }
    
    private function getDimensions($newWidth, $newHeight, $option)
    {
    switch ($option)
    {
    case 'exact':
    $optimalWidth = $newWidth;
    $optimalHeight= $newHeight;
    break;
    case 'portrait':
    $optimalWidth = $this->getSizeByFixedHeight($newHeight);
    $optimalHeight= $newHeight;
    break;
    case 'landscape':
    $optimalWidth = $newWidth;
    $optimalHeight= $this->getSizeByFixedWidth($newWidth);
    break;
    case 'auto':
    $optionArray = $this->getSizeByAuto($newWidth, $newHeight);
    $optimalWidth = $optionArray['optimalWidth'];
    $optimalHeight = $optionArray['optimalHeight'];
    break;
    case 'crop':
    $optionArray = $this->getOptimalCrop($newWidth, $newHeight);
    $optimalWidth = $optionArray['optimalWidth'];
    $optimalHeight = $optionArray['optimalHeight'];
    break;
    }
    return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
    }
    
    private function getSizeByFixedHeight($newHeight)
    {
    $ratio = $this->width / $this->height;
    $newWidth = $newHeight * $ratio;
    return $newWidth;
    }
    
    private function getSizeByFixedWidth($newWidth)
    {
    $ratio = $this->height / $this->width;
    $newHeight = $newWidth * $ratio;
    return $newHeight;
    }
    
    private function getSizeByAuto($newWidth, $newHeight)
    {
    if ($this->height < $this->width)
    {
    $optimalWidth = $newWidth;
    $optimalHeight= $this->getSizeByFixedWidth($newWidth);
    }
    elseif ($this->height > $this->width)
    {
    $optimalWidth = $this->getSizeByFixedHeight($newHeight);
    $optimalHeight= $newHeight;
    }
    else
    {
    if ($newHeight < $newWidth) {
    $optimalWidth = $newWidth;
    $optimalHeight= $this->getSizeByFixedWidth($newWidth);
    } else if ($newHeight > $newWidth) {
    $optimalWidth = $this->getSizeByFixedHeight($newHeight);
    $optimalHeight= $newHeight;
    } else {
    $optimalWidth = $newWidth;
    $optimalHeight= $newHeight;
    }
    }
    return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
    }
    
    private function getOptimalCrop($newWidth, $newHeight)
    {
    $heightRatio = $this->height / $newHeight;
    $widthRatio = $this->width / $newWidth;
    
    if ($heightRatio < $widthRatio) {
    $optimalRatio = $heightRatio;
    } else {
    $optimalRatio = $widthRatio;
    }
    $optimalHeight = $this->height / $optimalRatio;
    $optimalWidth = $this->width / $optimalRatio;
    return array('optimalWidth' => $optimalWidth, 'optimalHeight' => $optimalHeight);
    }
    
    private function crop($optimalWidth, $optimalHeight, $newWidth, $newHeight)
    {
    $cropStartX = ( $optimalWidth / 2) - ( $newWidth /2 );
    $cropStartY = ( $optimalHeight/ 2) - ( $newHeight/2 );
    $crop = $this->imageResized;
    $this->imageResized = imagecreatetruecolor($newWidth , $newHeight);
    imagecopyresampled($this->imageResized, $crop , 0, 0, $cropStartX, $cropStartY, $newWidth, $newHeight , $newWidth, $newHeight);
    }
    
    public function saveImage($savePath, $imageQuality="100")
    {
    $extension = strrchr($savePath, '.');
    $extension = strtolower($extension);
    
    switch($extension)
    {
    case '.jpg':
    case '.jpeg':
    if (imagetypes() & IMG_JPG) {
    imagejpeg($this->imageResized, $savePath, $imageQuality);
    }
    break;
    
    case '.gif':
    if (imagetypes() & IMG_GIF) {
    imagegif($this->imageResized, $savePath);
    }
    break;
    
    case '.png':
    $scaleQuality = round(($imageQuality/100) * 9);
    $invertScaleQuality = 9 - $scaleQuality;
    if (imagetypes() & IMG_PNG) {
    imagepng($this->imageResized, $savePath, $invertScaleQuality);
    }
    break;
    default:
    break;
    }
    imagedestroy($this->imageResized);
    }
    }
    ?>
    kullanımı ;

    include('boyutlandir.php');
    $resimyolu="resimler/ornek.png";
    $resizeObj = new resize($resimyolu);
    $resizeObj -> resizeImage(750, 500, 'auto');//boyut ayarla
    $resizeObj -> saveImage($resimyolu, 100);
    kırparak yapmak istersen

    include('boyutlandir.php');
    $resimyolu="resimler/ornek.png";
    $resizeObj = new resize($resimyolu);
    $resizeObj -> resizeImage(750, 500, 'crop');//kırparak ayarla
    $resizeObj -> saveImage($resimyolu, 100);
    resim kalitesini düşürmek istersen

    $resizeObj -> saveImage($resimyolu, 100);
    komutundaki 100 değerini 1 - 100 arasında bir değer atayarak kaydedebilirisin.