예제 #1
0
 public function testLoad()
 {
     // Loading an image (200x200) from Gravatar
     $img = new GDImage();
     $img_loaded = $img->load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=200.jpg');
     $this->assertTrue($img_loaded);
     return $img;
 }
예제 #2
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;
 }
예제 #3
0
파일: card.php 프로젝트: pranastae/gdimage
<?php

/**
 * Creating a Presentation Card
 */
require '../src/GDImage/GDUtils.php';
require '../src/GDImage/GDImage.php';
require '../src/GDImage/GDFigure.php';
require '../src/GDImage/GDText.php';
require '../src/GDImage/GDCanvas.php';
// Creating an avatar image
$avatar_image = new GDImage();
$avatar_image->load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=100.jpg');
$avatar_image->setTop(60);
$avatar_image->setLeft(70);
$about_text = new GDText("MY AWESOME PRESENTATION CARD GENERATED WITH GDIMAGE");
$about_text->setSize(16);
$about_text->setWidth(300);
$about_text->setLeft(210);
$about_text->setTop(75);
$about_text->setColor(204, 164, 116);
$about_text->setFontface('fonts/Lato-Lig.ttf');
$twitter_text = new GDText('@myname');
$twitter_text->setSize(11);
$twitter_text->setWidth(70);
$twitter_text->setLeft(450);
$twitter_text->setTop(210);
$twitter_text->setColor(130, 127, 125);
$twitter_text->setFontface('fonts/Lato-Reg.ttf');
$canvas_figure = new GDFigure(550, 250);
$canvas_figure->setBackgroundColor(47, 42, 39);