2017-02-26 7 views
0

私はprestashopでアップロード時に画像のサイズを変更しようとしましたが、うまく動作しません。 HERE イメージサイズ変更php prestashop

$images = count($_FILES['specialImg']['name']); 
     $minwidth = 1500; 
     $minheight = 1500; 
     if ($images <= Configuration::get('JMARKETPLACE_MAX_IMAGES')) { 
      for ($i=1; $i<=Configuration::get('JMARKETPLACE_MAX_IMAGES'); $i++) { 
       if ($_FILES['specialImg']['name'][$i] != "") { 
        if ((($_FILES['specialImg']['type'][$i] == "image/pjpeg") || 
         ($_FILES['specialImg']['type'][$i] == "image/jpeg") || 
         ($_FILES['specialImg']['type'][$i] == "image/png")) && 
         ($_FILES['specialImg']['size'][$i] < $this->return_bytes(ini_get('post_max_size')))) { 

         list($width, $height, $type, $attr) = getimagesize($_FILES['specialImg']['tmp_name'][$i]);  
//HERE IS MY RESIZE       
ImageManager::resize($_FILES['specialImg']['tmp_name'][$i], 200, 200); 

if ($width == $minwidth && $height == $minheight) { 
         $url_images[$i] = $_FILES['specialImg']['tmp_name'][$i]; 
        } 

は、関数のサイズを変更PrestaShopの、しかし、私は、ファイルがアップロードされていないが、サイズ変更され、エラーはそれを動作させるカントがありますか?!誰かがどのようにそれは私のスクリプトで完璧WORXこの機能で

public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg', 
          $force_type = false, &$error = 0, &$tgt_width = null, &$tgt_height = null, $quality = 5, 
          &$src_width = null, &$src_height = null) 
{ 
    if (PHP_VERSION_ID < 50300) { 
     clearstatcache(); 
    } else { 
     clearstatcache(true, $src_file); 
    } 

    if (!file_exists($src_file) || !filesize($src_file)) { 
     return !($error = self::ERROR_FILE_NOT_EXIST); 
    } 

    list($tmp_width, $tmp_height, $type) = getimagesize($src_file); 
    $rotate = 0; 
    if (function_exists('exif_read_data') && function_exists('mb_strtolower')) { 
     $exif = @exif_read_data($src_file); 

     if ($exif && isset($exif['Orientation'])) { 
      switch ($exif['Orientation']) { 
       case 3: 
        $src_width = $tmp_width; 
        $src_height = $tmp_height; 
        $rotate = 180; 
        break; 

       case 6: 
        $src_width = $tmp_height; 
        $src_height = $tmp_width; 
        $rotate = -90; 
        break; 

       case 8: 
        $src_width = $tmp_height; 
        $src_height = $tmp_width; 
        $rotate = 90; 
        break; 

       default: 
        $src_width = $tmp_width; 
        $src_height = $tmp_height; 
      } 
     } else { 
      $src_width = $tmp_width; 
      $src_height = $tmp_height; 
     } 
    } else { 
     $src_width = $tmp_width; 
     $src_height = $tmp_height; 
    } 

    // If PS_IMAGE_QUALITY is activated, the generated image will be a PNG with .jpg as a file extension. 
    // This allow for higher quality and for transparency. JPG source files will also benefit from a higher quality 
    // because JPG reencoding by GD, even with max quality setting, degrades the image. 
    if (Configuration::get('PS_IMAGE_QUALITY') == 'png_all' 
     || (Configuration::get('PS_IMAGE_QUALITY') == 'png' && $type == IMAGETYPE_PNG) && !$force_type) { 
     $file_type = 'png'; 
    } 

    if (!$src_width) { 
     return !($error = self::ERROR_FILE_WIDTH); 
    } 
    if (!$dst_width) { 
     $dst_width = $src_width; 
    } 
    if (!$dst_height) { 
     $dst_height = $src_height; 
    } 

    $width_diff = $dst_width/$src_width; 
    $height_diff = $dst_height/$src_height; 

    $ps_image_generation_method = Configuration::get('PS_IMAGE_GENERATION_METHOD'); 
    if ($width_diff > 1 && $height_diff > 1) { 
     $next_width = $src_width; 
     $next_height = $src_height; 
    } else { 
     if ($ps_image_generation_method == 2 || (!$ps_image_generation_method && $width_diff > $height_diff)) { 
      $next_height = $dst_height; 
      $next_width = round(($src_width * $next_height)/$src_height); 
      $dst_width = (int)(!$ps_image_generation_method ? $dst_width : $next_width); 
     } else { 
      $next_width = $dst_width; 
      $next_height = round($src_height * $dst_width/$src_width); 
      $dst_height = (int)(!$ps_image_generation_method ? $dst_height : $next_height); 
     } 
    } 

    if (!ImageManager::checkImageMemoryLimit($src_file)) { 
     return !($error = self::ERROR_MEMORY_LIMIT); 
    } 

    $tgt_width = $dst_width; 
    $tgt_height = $dst_height; 

    $dest_image = imagecreatetruecolor($dst_width, $dst_height); 

    // If image is a PNG and the output is PNG, fill with transparency. Else fill with white background. 
    if ($file_type == 'png' && $type == IMAGETYPE_PNG) { 
     imagealphablending($dest_image, false); 
     imagesavealpha($dest_image, true); 
     $transparent = imagecolorallocatealpha($dest_image, 255, 255, 255, 127); 
     imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $transparent); 
    } else { 
     $white = imagecolorallocate($dest_image, 255, 255, 255); 
     imagefilledrectangle($dest_image, 0, 0, $dst_width, $dst_height, $white); 
    } 

    $src_image = ImageManager::create($type, $src_file); 
    if ($rotate) { 
     $src_image = imagerotate($src_image, $rotate, 0); 
    } 

    if ($dst_width >= $src_width && $dst_height >= $src_height) { 
     imagecopyresized($dest_image, $src_image, (int)(($dst_width - $next_width)/2), (int)(($dst_height - $next_height)/2), 0, 0, $next_width, $next_height, $src_width, $src_height); 
    } else { 
     ImageManager::imagecopyresampled($dest_image, $src_image, (int)(($dst_width - $next_width)/2), (int)(($dst_height - $next_height)/2), 0, 0, $next_width, $next_height, $src_width, $src_height, $quality); 
    } 
    $write_file = ImageManager::write($file_type, $dest_image, $dst_file); 
    @imagedestroy($src_image); 
    return $write_file; 
} 

答えて

0

こんにちはルックことを行うと、透明画像を許可するように私に言うことができます:Resizing images php form

+0

私はあなたの機能を追加する場所? – jolo

+0

この関数を変更してください:このImageManager :: resize($ _ FILES ['specialImg'] ['tmp_name'] [$ i]、200,200)の代わりにpublic static関数のサイズ変更またはコードへの挿入。 –

関連する問題