コード例 #1
0
 static function makeImage($sourceFile, $destFile, $width, $height, $quality, $refresh, $crop = 0, $rotation = 0, $round = 0, $roundFill = '', $watermark = 0, $wmText = '', $wmTextColor = '', $wmTextSize = '', $wmFilename = '', $wmPosition = '', $wmTrans = 100)
 {
     if (!extension_loaded('gd') && !function_exists('gd_info')) {
         igFileHelper::raiseError('M1 0 :Please Check the PHP extension "GD Image Library" is installed on this server', $refresh);
         return false;
     }
     if ($width == 0 || $height == 0) {
         igFileHelper::raiseError('MI 1: ' . JText::_('Image Width Or Height In Profile Settings Must Not Be Zero'), $refresh);
         return false;
     }
     jimport('joomla.filesystem.file');
     require_once JPATH_ADMINISTRATOR . '/components/com_igallery/lib/gdimage/GdImage.php';
     if (!JFile::exists($destFile)) {
         $ext = JFile::getExt($sourceFile);
         $imageinfo = getimagesize($sourceFile);
         $image = GDImage::load($sourceFile);
         $params = JComponentHelper::getParams('com_igallery');
         $tryOriginal = $params->get('use_original', 0);
         if ($tryOriginal == 1) {
             if ($rotation == 0 && $round == 0 && $watermark == 0 && $crop == 0) {
                 if ($imageinfo[0] <= $width && $imageinfo[1] <= $height) {
                     if (!JFile::copy($sourceFile, $destFile)) {
                         igFileHelper::raiseError($sourceFile . ' -> ' . $destFile . ' ' . JText::_('Error Moving File To Directory'), $refresh);
                         return false;
                     }
                     return true;
                 }
             }
         }
         if ($crop == 1 && $imageinfo[0] > $width && $imageinfo[1] > $height) {
             $image = $image->resize((int) $width, (int) $height, 'outside')->crop('center', 'middle', (int) $width, (int) $height);
         } else {
             $image = $image->resize((int) $width, (int) $height, 'inside', 'down');
         }
         if ($rotation != 0) {
             if (!function_exists('imagerotate')) {
                 igFileHelper::raiseError(JFile::getName($sourceFile) . ': nee' / ' rotating ' . $rotation . ' degress, Please Check the php function "imagerotate" is available on this server', $refresh);
             } else {
                 $image = $image->rotate($rotation, null, false);
             }
         }
         if ($watermark == 1) {
             $positionArray = explode('_', $wmPosition);
             switch ($positionArray[0]) {
                 case 'left':
                     $leftIndent = '+5';
                     break;
                 case 'right':
                     $leftIndent = '-5';
                     break;
                 default:
                     $leftIndent = '';
             }
             switch ($positionArray[1]) {
                 case 'top':
                     $topIndent = '+5';
                     break;
                 case 'bottom':
                     $topIndent = '-5';
                     break;
                 default:
                     $topIndent = '';
             }
             if (strlen($wmText) > 0) {
                 $canvas = $image->getCanvas();
                 $fontPath = IG_ADMINISTRATOR_COMPONENT . '/fonts/font.ttf';
                 if (!JFile::exists($fontPath)) {
                     igFileHelper::raiseError('Watermarking Font File Missing, Please Upload a .ttf file to : ' . $fontPath, $refresh);
                     return false;
                 } else {
                     $colorArray = explode(',', $wmTextColor);
                     $font = new GDImage_Font_TTF($fontPath, (int) $wmTextSize, $image->allocateColorAlpha((int) $colorArray[0], (int) $colorArray[1], (int) $colorArray[2], 100 - $wmTrans));
                     $canvas->setFont($font);
                     $canvas->writeText($positionArray[0] . $leftIndent, $positionArray[1] . $topIndent, $wmText);
                 }
             }
             if (strlen($wmFilename) > 0) {
                 $extWatermark = JFile::getExt(IG_WATERMARK_PATH . '/' . $wmFilename);
                 $overlay = GDImage::load(IG_WATERMARK_PATH . '/' . $wmFilename);
                 $image = $image->merge($overlay, $positionArray[0], $positionArray[1], $wmTrans);
             }
         }
         if ($round == 1) {
             if (!function_exists('imagerotate')) {
                 igFileHelper::raiseError('Rounded Corners enabled: Please Check the php function "imagerotate" is available on this server', $refresh);
             } else {
                 if ($width < 200) {
                     $radius = 11;
                 } else {
                     $radius = 12;
                 }
                 $colorArray = explode(',', $roundFill);
                 $image = $image->roundCorners($radius, $image->allocateColor((int) $colorArray[0], (int) $colorArray[1], (int) $colorArray[2]), 255);
             }
         }
         if (preg_match("/jp/i", $ext)) {
             $image->saveToFile($destFile, $quality);
         } else {
             $image->saveToFile($destFile);
         }
         if ($rotation != 0) {
             $image = GDImage::load($destFile);
             $imageinfo = getimagesize($sourceFile);
             if ($imageinfo[0] > $width || $imageinfo[1] > $height) {
                 if ($crop == 1 && $imageinfo[0] > $width && $imageinfo[1] > $height) {
                     $image = $image->resize((int) $width, (int) $height, 'outside')->crop('center', 'middle', (int) $width, (int) $height);
                 } else {
                     $image = $image->resize((int) $width, (int) $height, 'inside', 'down');
                 }
             }
             $image->saveToFile($destFile);
         }
         return true;
     }
     return true;
 }
コード例 #2
0
 static function moveFile($tmpPath, $destDir, $fileName, $refresh)
 {
     $destPath = $destDir . '/' . $fileName;
     if (!JFile::upload($tmpPath, $destPath)) {
         igFileHelper::raiseError($tmpPath . ' -> ' . $destPath . ' ' . JText::_('Error Moving File To Directory'), $refresh);
         return false;
     }
     return true;
 }