Changeset 7291


Ignore:
Timestamp:
Oct 20, 2010, 10:45:14 AM (10 years ago)
Author:
plg
Message:

feature 1942 added: support PNG files for creating thumbnails

GD version 2 becomes mandatory

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/gvideo/admin/thumbnails.php

    r7284 r7291  
    4747    }
    4848
    49     $ver_info = gd_info();
    50     preg_match('/\d/', $ver_info['GD Version'], $gd_ver);
     49    $tempfile = $url;
     50    if (url_is_remote($url))
     51    {
     52      $tempfile = tempnam($path, 'jpg');
     53      fetchRemote($url, $tempfile_content);
     54      file_put_contents($tempfile, $tempfile_content);
     55    }
    5156
    52     if (!($tempfile = @tempnam( $path, 'jpg')
    53       and $handle = @fopen($tempfile, 'wb')
    54       and fetchRemote($url, $handle)
    55       and @fclose($handle)
    56       and $srcImage = @imagecreatefromjpeg($tempfile)))
     57    list($width, $height, $type) = getimagesize($tempfile);
     58    if (IMAGETYPE_PNG == $type)
    5759    {
    58       return false;
     60      $srcImage = imagecreatefrompng($tempfile);
    5961    }
    60     @unlink($tempfile);
     62    else
     63    {
     64      $srcImage = imagecreatefromjpeg($tempfile);
     65    }
     66   
     67    unlink($tempfile);
    6168
    6269    if (isset($_POST['add_band']))
     
    8996    }
    9097
    91     if ($gd_ver[0] >= 2)
     98    $destImage = imagecreatetruecolor($destWidth, $destHigh);
     99   
     100    imagecopyresampled(
     101      $destImage,
     102      $srcImage,
     103      0,
     104      0,
     105      0,
     106      0,
     107      $destWidth,
     108      $destHigh,
     109      $srcWidth,
     110      $srcHeight
     111      );
     112
     113    if (IMAGETYPE_PNG == $type)
    92114    {
    93         $destImage = imagecreatetruecolor($destWidth, $destHigh);
    94         imagecopyresampled($destImage, $srcImage, 0, 0, 0, 0,
    95             $destWidth, $destHigh, $srcWidth, $srcHeight);
     115      imagepng($destImage, $path);
    96116    }
    97117    else
    98118    {
    99         $destImage = imagecreate($destWidth, $destHigh);
    100         imagecopyresized($destImage, $srcImage, 0, 0, 0, 0,
    101             $destWidth, $destHigh, $srcWidth, $srcHeight);
     119      imagejpeg($destImage, $path, 95);
    102120    }
    103 
    104     imagejpeg($destImage, $path);
     121   
    105122    imagedestroy($srcImage);
    106123    imagedestroy($destImage);
Note: See TracChangeset for help on using the changeset viewer.