Esempio n. 1
1
function build_and_send_graph($data_rs, $chartType, $title)
{
    $gdImage = new GDImage(get_opendb_image_type());
    $imgType = $gdImage->getImageType();
    unset($gdImage);
    $graphCfg = _theme_graph_config();
    $chart = new StatsChartImpl($chartType, $graphCfg);
    $chart->setTitle($title);
    if (is_array($data_rs)) {
        usort($data_rs, "sort_data_element");
        // only show first 12 items - otherwise graph will not render correctly.
        if ($chartType == 'piechart' && count($data_rs) > 12) {
            $data_rs = array_slice($data_rs, 0, 11);
        }
        reset($data_rs);
        while (list(, $data_r) = each($data_rs)) {
            if ($chartType == 'piechart') {
                $chart->addData($data_r['display'] . " ({$data_r['value']})", $data_r['value']);
            } else {
                $chart->addData($data_r['display'], $data_r['value']);
            }
        }
    }
    $chart->render($imgType);
}
 /**
  * Returns the path to the library
  *
  * @return string
  */
 static function path()
 {
     if (self::$path === null) {
         self::$path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
     }
     return self::$path;
 }
Esempio n. 3
1
 public function __construct($message, $iWidth = null, $iHeight = null)
 {
     $iFont = 2;
     if ($message instanceof Exception) {
         $message = $message->getMessage();
         if (defined('DEBUG') && DEBUG) {
             $message .= "\n" . $message->getTraceAsString();
         }
     }
     // calculate image size
     if ($iWidth == null || $iHeight != null) {
         $aMessage = explode("\n", $message);
         $iFontWidth = imagefontwidth($iFont);
         $iFontHeight = imagefontheight($iFont);
         foreach ($aMessage as $sLine) {
             $iHeight += $iFontHeight + 1;
             $iMessageWidth = $iFontWidth * (strlen($sLine) + 1);
             if ($iMessageWidth > $iWidth) {
                 $iWidth = $iMessageWidth;
             }
         }
         $iHeight += 8;
     }
     parent::__construct($iWidth, $iHeight);
     $iFontColor = $this->getColor(255, 0, 0);
     $iBorderColor = $this->getColor(255, 0, 0);
     $iBGColor = $this->getColor(255, 255, 255);
     $iPadding = 4;
     $this->fill(0, 0, $iBGColor);
     $this->drawRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $iBorderColor);
     $this->drawText($message, $iFont, $iFontColor, $iPadding, $iPadding);
 }
Esempio n. 4
0
 function testImageCreate()
 {
     $gdImage = new GDImage('png');
     $this->assertEquals(FALSE, $gdImage->createImage('code_bg.png'));
     $this->assertEquals(TRUE, $gdImage->createImage('code_bg'));
     $this->assertEquals('./images/code_bg.png', $gdImage->getImageSrc());
     print_r($gdImage->getErrors());
 }
Esempio n. 5
0
function render_secret_image($random_num)
{
    $gdImage = new GDImage(get_opendb_image_type());
    $gdImage->createImage('code_bg');
    $image =& $gdImage->getImage();
    $text_color = ImageColorAllocate($image, 80, 80, 80);
    header("Cache-control: no-store");
    header("Pragma: no-store");
    header("Expires: 0");
    CenterImageString($image, 100, get_secret_image_code($random_num), 5, 7, $text_color);
    $gdImage->sendImage();
    unset($gdImage);
}
Esempio n. 6
0
/**
 * 创建图片
 * @param $uploadedfile 需生成的图片路径
 * @param $name 生成后的返回的图片名称
 * @param $path 需要存放的图片上级目录
 * @param $size 缩略图的尺寸(array)
 * @param $max_pixel 尺寸的最大值(M)
 * return 生成后的图片名
 */
function hg_mk_images($uploadedfile, $name, $path, $size, $max_pixel = 2)
{
    if (!$uploadedfile || !$name || !$path || !is_array($size)) {
        return OBJECT_NULL;
    }
    include_once ROOT_PATH . 'lib/class/gdimage.php';
    //源文件
    if (filesize($uploadedfile) / 1024 / 1024 >= $max_pixel) {
        return PIXEL_ERROR;
    }
    $image = getimagesize($uploadedfile);
    $width = $image[0];
    $height = $image[1];
    $file_name = $name;
    //目录
    $file_dir = $path;
    //文件路径
    $file_path = $file_dir . $file_name;
    if (!hg_mkdir($file_dir)) {
        return UPLOAD_ERR_NO_FILE;
    }
    if (!copy($uploadedfile, $file_path)) {
        return UPLOAD_ERR_NO_FILE;
    }
    $img = new GDImage($file_path, $file_path, '');
    foreach ($size as $key => $value) {
        $new_name = $value['label'] . $file_name;
        $save_file_path = $file_dir . $new_name;
        $img->init_setting($file_path, $save_file_path, '');
        $img->maxHeight = $value['height'];
        $img->maxWidth = $value['width'];
        /*
        	if($width > $height)
        	{
        		$img->maxWidth = $width > $value['width']?$value['width'] : $width;
        		$img->maxHeight = $height * ($img->maxWidth/$width);
        	}
        	else 
        	{
        		$img->maxHeight = $height > $value['height']?$value['height'] : $height;
        		$img->maxWidth = $width * ($img->maxHeight/$height);
        	}
        */
        $img->makeThumb(3);
    }
    return $file_name;
}
Esempio n. 7
0
 /**
  * 上传文件
  * @author	肖飞
  * @param array	 	$arrFile			图片文件信息数组$_FILES
  * @param int 		$PR					自动压缩的比例
  * @param int		$intID				内容ID,标示新增还是修改
  * @return unknown
  */
 function uploadInfoImage($arrFile, $PR = 0, $intID = 0)
 {
     if ($arrFile['name']) {
         if (!in_array(strtolower($arrFile['type']), array('image/jpg', 'image/jpeg', 'image/gif', 'image/pjpeg', 'image/png', 'image/x-png', 'application/x-shockwave-flash'))) {
             check::AlertExit('文件类型不符合要求(' . $arrFile['type'] . ')', -1);
         }
     }
     if ($intID == 0) {
         $intID = $this->getMaxID();
     }
     $strDir = ceil($intID / 1000);
     $strMakeDir = $this->arrGPic['FileSavePath'] . $strDir;
     if (!is_dir($this->arrGPic['FileSavePath'])) {
         @mkdir($this->arrGPic['FileSavePath']);
         @chmod($this->arrGPic['FileSavePath'], 0777);
     }
     if (!is_dir($strMakeDir)) {
         @mkdir($strMakeDir);
         @chmod($strMakeDir, 0777);
     }
     $FileExt = strrchr($arrFile['name'], ".");
     //取得上传文件扩展名
     $strPhoto = $strDir . "/" . $intID . "_" . time() . $FileExt;
     //存入数据库的图片访问路径
     $strPicName = $strMakeDir . "/" . $intID . "_" . time() . $FileExt;
     //新图片路径及名称
     if ($arrFile['type'] != 'application/x-shockwave-flash' && $arrFile['size'] > $this->arrGPic['FileMaxSize']) {
         if ($PR != 0) {
             move_uploaded_file($arrFile['tmp_name'], $strPicName);
             $objGDImage = new GDImage();
             if ($objGDImage->makePRThumb($strPicName, $PR)) {
                 return $strPhoto;
             } else {
                 check::AlertExit($strPicName . "文件上传错误!", -1);
             }
         } else {
             check::AlertExit("文件大小不符合要求!", -1);
         }
     } else {
         if (move_uploaded_file($arrFile['tmp_name'], $strPicName)) {
             return $strPhoto;
         } else {
             check::AlertExit($strPicName . "文件上传错误!", -1);
         }
     }
 }
 /**
  * (non-PHPdoc)
  * @see GDImage_Image#asTrueColor()
  */
 function asTrueColor()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $new = GDImage::createTrueColorImage($width, $height);
     if ($this->isTransparent()) {
         $new->copyTransparencyFrom($this);
     }
     imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height);
     return $new;
 }
 public function __construct($sMessage)
 {
     parent::__construct(246, 48);
     $sMessage = wordwrap(strip_tags($sMessage), 40, "\n", true);
     $iFontColor = $this->getColor(255, 0, 0);
     $iBorderColor = $this->getColor(255, 0, 0);
     $iBGColor = $this->getColor(255, 255, 255);
     $iPadding = 4;
     $this->fill(0, 0, $iBGColor);
     $this->drawRectangle(0, 0, $this->getWidth() - 1, $this->getHeight() - 1, $iBorderColor);
     $this->drawText($sMessage, 2, $iFontColor, $iPadding, $iPadding);
 }
Esempio n. 10
0
function crop_media($image_media, $width, $height)
{
    if (empty($image_media)) {
        return;
    }
    list($image_path, $modified_path, $modified_media) = _media_filenames($image_media, '-crop-' . $width . 'x' . $height);
    if (!file_exists($image_path)) {
        return;
    }
    if (!file_exists($modified_path) || filemtime($modified_path) < filemtime($image_path)) {
        $image = new GDImage($image_path);
        // preserve aspect ratio
        $old_width = (double) $image->width;
        $old_height = (double) $image->height;
        $old_ratio = $old_width / $old_height;
        $new_width = (double) $width;
        $new_height = (double) $height;
        $new_ratio = $width / $height;
        // figure out whether to keep width or height.
        if ($old_ratio < $new_ratio) {
            $image->resize($width, 0, false);
            $crop = ($image->height - $height) / 2;
            $image->crop(0, $crop, $width, $crop + $height);
        } else {
            if ($old_ratio > $new_ratio) {
                $image->resize(0, $height, false);
                $crop = ($image->width - $width) / 2;
                $image->crop($crop, 0, $crop + $width, $height);
            }
        }
        // end preserve aspect ratio
        $image->save($modified_path);
    }
    return $modified_media;
}
 static function get($operationName)
 {
     $lcname = strtolower($operationName);
     if (!isset(self::$cache[$lcname])) {
         $opClassName = "GDImage_Operation_" . $operationName;
         if (!class_exists($opClassName, false)) {
             $fileName = GDImage::path() . 'Operation/' . ucfirst($operationName) . '.php';
             if (file_exists($fileName)) {
                 require_once $fileName;
             } else {
                 JError::raiseError(500, JText::sprintf('JLIB_GDIMAGE_ERROR_LOAD_OPERATION', $operationName));
                 return false;
             }
         }
         self::$cache[$lcname] = new $opClassName();
     }
     return self::$cache[$lcname];
 }
 /**
  * Returns a mapper, based on the $uri and $format
  * 
  * @param string $uri File URI
  * @param string $format File format (extension or mime-type) or null
  * @return GDImage_Mapper
  **/
 static function selectMapper($uri, $format = null)
 {
     $format = self::determineFormat($uri, $format);
     if (array_key_exists($format, self::$mappers)) {
         return self::$mappers[$format];
     }
     $mapperClassName = 'GDImage_Mapper_' . $format;
     if (!class_exists($mapperClassName, false)) {
         $mapperFileName = GDImage::path() . 'Mapper/' . $format . '.php';
         if (file_exists($mapperFileName)) {
             require_once $mapperFileName;
         }
     }
     if (class_exists($mapperClassName, false)) {
         self::$mappers[$format] = new $mapperClassName();
         return self::$mappers[$format];
     }
     JError::raiseError(500, JText::sprintf('JLIB_GDIMAGE_ERROR_FORMAT_NOT_SUPPORTED', $format));
 }
 /**
  * @param GDImage_Image $image
  * @param int $radius
  * @param int $color
  * @param int $smoothness
  * @return GDImage_Image
  */
 function execute($image, $radius, $color, $smoothness, $corners)
 {
     if ($smoothness < 1) {
         $sample_ratio = 1;
     } elseif ($smoothness > 16) {
         $sample_ratio = 16;
     } else {
         $sample_ratio = $smoothness;
     }
     $corner = GDImage::createTrueColorImage($radius * $sample_ratio, $radius * $sample_ratio);
     if ($color === null) {
         imagepalettecopy($corner->getHandle(), $image->getHandle());
         $bg_color = $corner->allocateColor(0, 0, 0);
         $corner->fill(0, 0, $bg_color);
         $fg_color = $corner->allocateColor(255, 255, 255);
         $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color);
         $corner = $corner->resize($radius, $radius);
         $result = $image->asTrueColor();
         $tc = $result->getTransparentColor();
         if ($tc == -1) {
             $tc = $result->allocateColorAlpha(255, 255, 255, 127);
             imagecolortransparent($result->getHandle(), $tc);
             $result->setTransparentColor($tc);
         }
         if ($corners & GDImage::SIDE_TOP_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_TOP) {
             $result = $result->applyMask($corner, -1, -1);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_TOP_RIGHT || $corners & GDImage::SIDE_TOP || $corners & GDImage::SIDE_RIGHT) {
             $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_RIGHT || $corners & GDImage::SIDE_RIGHT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->applyMask($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->applyMask($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         return $result;
     } else {
         $bg_color = $color;
         $corner->fill(0, 0, $bg_color);
         $fg_color = $corner->allocateColorAlpha(127, 127, 127, 127);
         $corner->getCanvas()->filledEllipse($radius * $sample_ratio, $radius * $sample_ratio, $radius * 2 * $sample_ratio, $radius * 2 * $sample_ratio, $fg_color);
         $corner = $corner->resize($radius, $radius);
         $result = $image->copy();
         if ($corners & GDImage::SIDE_TOP_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_TOP) {
             $result = $image->merge($corner, -1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_TOP_RIGHT || $corners & GDImage::SIDE_TOP || $corners & GDImage::SIDE_RIGHT) {
             $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, -1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_RIGHT || $corners & GDImage::SIDE_RIGHT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->merge($corner, $result->getWidth() - $corner->getWidth() + 1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         $corner = $corner->rotate(90);
         if ($corners & GDImage::SIDE_BOTTOM_LEFT || $corners & GDImage::SIDE_LEFT || $corners & GDImage::SIDE_BOTTOM) {
             $result = $result->merge($corner, -1, $result->getHeight() - $corner->getHeight() + 1, 100);
         }
         return $result;
     }
 }
Esempio n. 14
0
 public function createFile($water_id, $app_bundle, $filepath, $filename, $bs = "")
 {
     $imgdir = hg_getimg_dir($bs);
     $filepath = $imgdir . app_to_dir($app_bundle) . $filepath;
     $exttmp = explode('.', $filename);
     $json_file = $filepath . $exttmp[0] . '.json';
     $json = array();
     if (file_exists($json_file)) {
         $json = json_decode(file_get_contents($json_file), true);
     }
     $sql = "SELECT * FROM " . DB_PREFIX . "water_config WHERE id=" . $water_id;
     $ret = $this->db->query_first($sql);
     $json['water'] = array('type' => $ret['type'], 'filename' => $ret['filename'], 'opacity' => $ret['opacity'], 'position' => $ret['position'], 'water_text' => $ret['water_text'], 'water_font' => $ret['water_font'], 'font_size' => $ret['font_size'], 'water_color' => $ret['water_color'], 'water_angle' => $ret['water_angle'], 'margin_x' => $ret['margin_x'], 'margin_y' => $ret['margin_y'], 'condition_x' => $ret['condition_x'], 'condition_y' => $ret['condition_y']);
     hg_file_write($json_file, json_encode($json));
     copy($filepath . $filename, $filepath . 'nowater_' . $filename);
     include_once ROOT_PATH . 'lib/class/gdimage.php';
     $img = new GDImage();
     if ($json['water']['type'] == 1) {
         $json['water']['water_file_path'] = $json['water']['filename'] ? hg_getimg_default_dir() . WATER_PATH . $json['water']['filename'] : '';
         //根据图片大小和图片水印比例调整水印图片大小
         if ($this->settings['image_water_ratio'] && $json['water']['water_file_path']) {
             $img_info = getimagesize($filepath . $filename);
             $waterimg_info = getimagesize($json['water']['water_file_path']);
             if ($img_info[0] / $waterimg_info[0] < $this->settings['image_water_ratio']) {
                 $new_width = abs(intval($img_info[0] / $this->settings['image_water_ratio']));
                 hg_mk_images($json['water']['water_file_path'], $json['water']['filename'], hg_getimg_default_dir() . WATER_PATH . $new_width . '/', array('width' => $new_width, 'height' => ''), array());
                 $json['water']['water_file_path'] = hg_getimg_default_dir() . WATER_PATH . $new_width . '/' . $json['water']['filename'];
             }
         }
         $img->waterimg($filepath . $filename, $json['water']);
     } else {
         $json['water']['water_font'] = $json['water']['water_font'] ? CUR_CONF_PATH . 'font/' . $json['water']['water_font'] : CUR_CONF_PATH . 'font/arial.ttf';
         $json['water']['font_size'] = $json['water']['font_size'] ? $json['water']['font_size'] : 14;
         $img->waterstr($filepath . $filename, $json['water']);
     }
     return true;
 }
Esempio n. 15
0
 public function flip($iMode)
 {
     $iWidth = $this->getWidth();
     $iHeight = $this->getHeight();
     $src_x = 0;
     $src_y = 0;
     $src_width = $iWidth;
     $src_height = $iHeight;
     switch ($iMode) {
         case 1:
             //vertical
             $src_y = $iHeight - 1;
             $src_height = -$iHeight;
             break;
         case 2:
             //horizontal
             $src_x = $iWidth - 1;
             $src_width = -$iWidth;
             break;
         case 3:
             //both
             $src_x = $iWidth - 1;
             $src_y = $iHeight - 1;
             $src_width = -$iWidth;
             $src_height = -$iHeight;
             break;
         default:
             return;
     }
     $imgdest = new GDImage($iWidth, $iHeight);
     $imgdest->setAntiAlias($this->isAntiAlias());
     $imgdest->setAlphaBlending($this->isAlphaBlending());
     $imgdest->set8BitAlpha($this->is8BitAlpha());
     $imgdest->copyResampled($this, 0, 0, $src_x, $src_y, $iWidth, $iHeight, $src_width, $src_height);
     $this->replace($imgdest);
 }
Esempio n. 16
0
 private function drawErrorMessage($sMessage)
 {
     // settings
     $iFontSizeNormal = $this->oThemeConfig->getInteger('theme.text.size.normal');
     $sFontFileNormal = $this->oThemeConfig->getString('theme.text.font.normal');
     $sFontColorError = $this->oThemeConfig->getString('theme.text.color.error');
     $bFontAntiAlias = $this->oThemeConfig->getInteger('theme.text.anti-alias');
     $fLineSpacing = $this->oThemeConfig->getFloat('theme.text.line-spacing');
     // destroy old image
     $this->destroy();
     // create new image
     $this->loadPng($this->aThemeFiles['background']);
     // enable alpha
     $this->setAlphaBlending(true);
     $this->setSaveFullAlpha(true);
     // draw error icon
     $errorIcon = new GDImage();
     $errorIcon->loadPng($this->aThemeFiles['error']);
     $this->copy($errorIcon, 8, $this->getHeight() / 2 - 8);
     $errorIcon->destroy();
     // allocate color
     $iFontColor = $this->getColorHex($sFontColorError, $bFontAntiAlias);
     // draw text
     $this->drawTextFT($sMessage, $sFontFileNormal, $iFontSizeNormal, 0, $iFontColor, 30, $this->getHeight() / 2, array('linespacing' => $fLineSpacing));
 }
Esempio n. 17
0
 /**
  * Constructs a new Canvas.
  * @param mixed $element Only GDImage or GDFigure class
  * @access public
  * @return void
  */
 function __construct($element = NULL)
 {
     parent::__construct($element);
 }
Esempio n. 18
0
<?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);
Esempio n. 19
0
    include_once 'include/foot.php';
    exit;
}
$intID = intval($_GET['id']);
$arrInfo = $objWebInit->getInfo($intID, '*', 1, true);
include_once 'include/title.php';
include_once 'include/head.php';
$myText = new HAW_text("标题:" . $arrInfo['title']);
$objHaw->add_text($myText);
if (!empty($arrInfo['photo']) && $intCPage == 1) {
    $strWapPhoto = $arrGPic['FileSavePath'] . 'wap/' . $arrInfo['photo'];
    if (!is_file($strWapPhoto)) {
        //生成压缩图
        check::make_dir($strWapPhoto);
        copy($arrGPic['FileSavePath'] . '/b/' . $arrInfo['photo'], $strWapPhoto);
        $objGDImage = new GDImage();
        if ($objGDImage->makePRThumb($strWapPhoto, 0, $arrMHaw['image_width'], $arrMHaw['image_height'])) {
            $myImage = new HAW_image("photo.wbmp", $arrGPic['FileCallPath'] . 'wap/' . $arrInfo['photo'], $arrInfo['title']);
            $myImage->set_br(1);
            $myImage->set_html_width($arrMHaw['image_width']);
            $objHaw->add_image($myImage);
        }
    } else {
        $myImage = new HAW_image("photo.wbmp", $arrGPic['FileCallPath'] . 'wap/' . $arrInfo['photo'], $arrInfo['title']);
        $myImage->set_br(1);
        $myImage->set_html_width($arrMHaw['image_width']);
        $objHaw->add_image($myImage);
    }
}
$arrData = check::WordPage($arrInfo['intro'], $arrMHaw['detail_charnum'], $intCPage);
$myText = new HAW_text($arrData['centent']);
Esempio n. 20
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;
 }
Esempio n. 21
0
 /**
  * 头像生成接口
  * @return array  头像地址
  */
 public function uploadImage()
 {
     if (!$this->input['user_id']) {
         $userinfo = $this->mUser->verify_credentials();
     } else {
         $userinfo['id'] = intval($this->input['user_id']);
     }
     if (!$userinfo['id']) {
         $this->errorOutput(USENAME_NOLOGIN);
     }
     $files = $_FILES['files'];
     include_once ROOT_DIR . 'lib/class/gdimage.php';
     //源文件
     $uploadedfile = $files['tmp_name'];
     //源文件类型
     $tmp = explode('.', $uploadedfile);
     $file_type = $tmp[1];
     //文件名
     $file_name = $userinfo['id'] . ".jpg";
     //目录
     $file_dir = AVATAR_DIR . ceil($userinfo['id'] / NUM_IMG) . "/";
     //文件路径
     $file_path = $file_dir . $file_name;
     $size = array("larger" => array(LARGER_IMG_WIDTH, LARGER_IMG_HEIGHT), "middle" => array(MIDDLE_IMG_WIDTH, MIDDLE_IMG_HEIGHT), "small" => array(SMALL_IMG_WIDTH, SMALL_IMG_HEIGHT));
     if (!hg_mkdir($file_dir)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     if (!move_uploaded_file($uploadedfile, $file_path)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     //如果传递了裁剪信息
     if ($this->input['cut_info']) {
         $cut_info = urldecode($this->input['cut_info']);
         $info = explode(',', $cut_info);
         //裁剪的起点坐标
         $src_x = $info[0];
         $src_y = $info[1];
         //裁剪图片的大小
         $src_w = $info[2];
         $src_h = $info[3];
         $src_img = imagecreatefromjpeg($file_path);
         $dst_img = imageCreateTrueColor($src_w, $src_h);
         imageCopy($dst_img, $src_img, 0, 0, $src_x, $src_y, $src_w, $src_h);
         imageJPEG($dst_img, $file_path, 100);
     }
     $img = new GDImage($file_path, $file_path, '');
     $info = array();
     foreach ($size as $key => $value) {
         $save_file_path = $file_dir . $key . '_' . $file_name;
         $img->init_setting($file_path, $save_file_path, '');
         $img->maxWidth = $value[0];
         $img->maxHeight = $value[1];
         $img->makeThumb(3, false);
         $info[$key] = AVATAR_URL . ceil($userinfo['id'] / NUM_IMG) . "/" . $key . '_' . $file_name . "?" . hg_rand_num(7);
     }
     $info['ori'] = AVATAR_URL . ceil($userinfo['id'] / NUM_IMG) . "/" . $file_name . "?" . hg_rand_num(7);
     $sql = "UPDATE " . DB_PREFIX . "member \r\n\t\tSET avatar = '" . $userinfo['id'] . ".jpg' \r\n\t\tWHERE id=" . $userinfo['id'];
     $this->db->query($sql);
     $info['id'] = $userinfo['id'];
     $this->setXmlNode('img', 'imagefile');
     $this->addItem($info);
     return $this->output();
 }
Esempio n. 22
0
 public function run()
 {
     $bDebug = defined('DEBUG') && DEBUG;
     try {
         // get profile URL
         $sXmlUrl = $this->getProfileUrl(false);
         // load config
         $oCommonConfig = FileConfig::getInstance('common.cfg');
         $oImageConfig = FileConfig::getInstance('image.cfg');
         $oGPCConfig = GPCConfig::getInstance('get');
         // load config vars
         $iCacheLifetime = $oCommonConfig->getInteger('cache.lifetime', 600);
         $sCacheDir = $oCommonConfig->getString('cache.dir', 'cache');
         $bImageFallback = $oImageConfig->getString('image.fallback', true);
         $sDefaultLayout = $oImageConfig->getString('image.layout.default', 'small');
         $sDefaultTheme = $oImageConfig->getString('image.theme.default', 'default');
         $sLayout = $oGPCConfig->getStringAlnum('layout', $sDefaultLayout);
         $sTheme = $oGPCConfig->getStringAlnum('theme', $sDefaultTheme);
         // init cache
         $oImageCache = new Cache($sCacheDir, $iCacheLifetime, 'png');
         $oImageFile = $oImageCache->getFile($_SERVER['QUERY_STRING']);
         $sImageBase = 'image/layouts';
         if (!file_exists("{$sImageBase}/{$sLayout}")) {
             if (!file_exists("{$sImageBase}/{$sDefaultLayout}")) {
                 throw new RuntimeException('Default layout folder not found');
             }
             $sLayout = $sDefaultLayout;
         }
         $sLayoutDir = "{$sImageBase}/{$sLayout}";
         include "{$sLayoutDir}/SteamProfileImage.php";
         try {
             // do we have a cached version of the profile image?
             if (!$oImageFile->isCached()) {
                 $oProfileImage = new SteamProfileImage();
                 // try to generate the profile image
                 $oProfileImage->createProfile($sXmlUrl, $sLayoutDir, $sTheme);
                 // save it to cache
                 $oProfileImage->toPng($oImageFile->getPath());
                 // clear stat cache to ensure that the rest of the
                 // script will notice the file modification
                 clearstatcache();
             }
             $this->displayImage($oImageFile);
         } catch (SteamProfileImageException $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but a themed error image could have been generated
             try {
                 // try a fallback to the cached image first
                 if ($bImageFallback && $oImageFile->exists()) {
                     $this->displayImage($oImageFile);
                 } else {
                     // try to display the error image
                     $oProfileImage->toPng();
                 }
             } catch (Exception $f) {
                 // didn't work, re-throw the source exception
                 throw $e;
             }
         } catch (Exception $e) {
             // on debug mode, re-throw
             if ($bDebug) {
                 $ep = $e->getPrevious();
                 throw $ep == null ? $e : $ep;
             }
             // an exception was thrown in SteamProfileImage,
             // but we could try a fallback to the cached image
             if ($bImageFallback && $oImageFile->exists()) {
                 // redirect to cached image file
                 $this->displayImage($oImageFile);
             } else {
                 // nothing cached, re-throw exception
                 throw $e;
             }
         }
     } catch (Exception $e) {
         // quite fatal error, try to render a fail-safe error image
         if ($bDebug || !GDImage::isAvailable()) {
             $oHeader = new HTTPHeader();
             $oHeader->setResponse('Content-Type', 'text/plain');
             echo $bDebug ? "{$e}\n" : $e->getMessage();
         } else {
             $ErrorImage = new ErrorImage($e->getMessage());
             $ErrorImage->toPng();
         }
     }
 }
Esempio n. 23
0
 /**
  * @return bool True, if the image object holds a valid GD image, false otherwise
  */
 function isValid()
 {
     return GDImage::isValidImageHandle($this->handle);
 }
Esempio n. 24
0
 public static function createText($text, $font, $size, $color, $bg, $adjx = 0, $adjy = 0)
 {
     $c = self::ttfBox($text, $font, $size);
     $width = $c['tr_x'] - $c['tl_x'];
     $height = $c['bl_y'] - $c['tl_y'];
     $gd = new GDImage($width, $height, $bg);
     $gd->write($text, $font, $size, $color, $height - $c['bl_y'] + $adjy, 0 - $c['bl_x'] + $adjx);
     return $gd;
 }
Esempio n. 25
0
function hg_turn_img($file_path, $save_file_path, $direction)
{
    include_once ROOT_PATH . 'lib/class/gdimage.php';
    $angle = '';
    switch ($direction) {
        case 1:
            //左旋转
            $angle = '90';
            break;
        case 2:
            //右旋转
            $angle = '-90';
            break;
        case 3:
            //180度 掉头
            $angle = '180';
            break;
        default:
            return false;
            break;
    }
    $img = new GDImage();
    $img->init_setting($file_path, $save_file_path, '', $angle);
    $img->turnImg();
    return true;
}
Esempio n. 26
0
 /**
  *修改视频图片 
  */
 public function update_schematic()
 {
     $userinfo = $this->mUser->verify_credentials();
     if (!$userinfo['id']) {
         $this->errorOutput(USENAME_NOLOGIN);
     }
     $video_id = intval(trim($this->input['video_id']));
     $file_name = urldecode($this->input['schematic']);
     if (!$video_id) {
         $this->errorOutput(OBJECT_NULL);
     }
     $files = $_FILES['files'];
     include_once ROOT_DIR . 'lib/class/gdimage.php';
     //源文件
     $uploadedfile = $files['tmp_name'];
     $image = getimagesize($uploadedfile);
     $width = $image[0];
     $height = $image[1];
     $size = array("big" => array('t' => "b_", 'width' => VIDEO_IMG_WIDTH * VIDEO_IMG_MULTIPLE, 'height' => VIDEO_IMG_HEIGHT * VIDEO_IMG_MULTIPLE), "normal" => array('t' => "n_", 'width' => VIDEO_IMG_WIDTH, 'height' => VIDEO_IMG_HEIGHT));
     //文件名
     if (!$file_name) {
         $file_name = hg_generate_user_salt(16) . ".jpg";
     } else {
         str_replace(DOMAIN, "", $file_name, $cnt);
         if ($cnt) {
             $file_name = hg_generate_user_salt(16) . ".jpg";
         } else {
             $arr = explode("/", $file_name);
             $file_name = substr($arr[count($arr) - 1], 2);
             if (!trim($file_name)) {
                 $file_name = hg_generate_user_salt(16) . ".jpg";
             }
         }
     }
     //目录
     $file_dir = UPLOAD_DIR . VIDEO_DIR . ceil($video_id / NUM_IMG) . "/";
     //文件路径
     $file_path = $file_dir . $file_name;
     if (!hg_mkdir($file_dir)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     if (!copy($uploadedfile, $file_path)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     $img = new GDImage($file_path, $file_path, '');
     $info = array();
     foreach ($size as $key => $value) {
         $new_name = $value['t'] . $file_name;
         $save_file_path = $file_dir . $new_name;
         $img->init_setting($file_path, $save_file_path, '');
         $img->maxWidth = $value['width'];
         $img->maxHeight = $value['height'];
         $img->makeThumb(3, false);
         $info[$key] = UPLOAD_URL . VIDEO_DIR . ceil($video_id / NUM_IMG) . "/" . $new_name . "?" . hg_generate_user_salt(5);
     }
     $sql = "UPDATE " . DB_PREFIX . "video SET bschematic = '" . $file_name . "' , schematic = '" . $file_name . "' WHERE id = " . $video_id;
     $info['ori'] = $file_name;
     $info['id'] = $video_id;
     $this->db->query($sql);
     $this->setXmlNode('media', 'info');
     $this->addItem($info);
     return $this->output();
 }
Esempio n. 27
0
 /**
  * @depends testLoad
  */
 public function testDestroyResource(GDImage $img)
 {
     $img->destroy();
     $this->assertNull($img->getResource());
 }
Esempio n. 28
0
<?php

/**
 * Rotate an image
 */
require '../src/GDImage/GDUtils.php';
require '../src/GDImage/GDImage.php';
// Rotate an image to 90º
$image = new GDImage();
$image->load('http://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?s=100.jpg');
$image->rotate(90);
$image->output();
Esempio n. 29
0
                break;
            case 2:
                header("Content-type: image/png");
                imagepng($this->image);
                break;
            case 3:
                header("Content-type: image/gif");
                imagegif($this->image);
                break;
            default:
                header("Content-type: image/jpeg");
                imagejpeg($this->image);
                break;
        }
        // imagepng($this->image);
    }
    public function test()
    {
        echo __DIR__;
    }
    public function __destruct()
    {
        if ($this->image) {
            $res = imagedestroy($this->image);
            error_log($res, 3, __DIR__ . '/log.log');
        }
    }
}
$data = array('column0' => 'weight', 'column1' => 'yuanjia', 'column2' => 'huodognjia', 'servicePriceName' => 'meirong(hanxizao)', 'canUseMemberPrice' => '', 'canUseDiscountPrice' => '', 'is_default' => 0, 'serviceId' => 9, 'list' => array(array('name' => 'jianzhijia', 'price' => 20.0, 'discountPirce' => 2.0), array('name' => 'yuanjia', 'price' => 30.0, 'discountPirce' => 3.0), array('name' => 'huodongjia', 'price' => 40.0, 'discountPirce' => 4.0)));
$gdImage = new GDImage();
$gdImage->getPicture($data);
Esempio n. 30
0
 private function handle($uploadedfile)
 {
     include_once ROOT_DIR . 'lib/class/gdimage.php';
     //源文件
     if (filesize($uploadedfile) / 1024 / 1024 >= IMG_SIZE) {
         $this->errorOutput(IMG_SIZE_ERROR);
     }
     $image = getimagesize($uploadedfile);
     $width = $image[0];
     $height = $image[1];
     if (strpos(strtolower($image['mime']), 'jpeg')) {
         $type = '.jpg';
     } else {
         if (strpos(strtolower($image['mime']), 'png')) {
             $type = '.png';
         } else {
             if (strpos(strtolower($image['mime']), 'gif')) {
                 $type = '.gif';
             }
         }
     }
     //文件名
     $file_name = hg_generate_user_salt(16) . ".jpg";
     $size = array("larger" => array('t' => "l_", 'size' => IMG_SIZE_LARGER), "middle" => array('t' => "m_", 'size' => IMG_SIZE_MIDDLE), "small" => array('t' => "s_", 'size' => IMG_SIZE_SMALL));
     //目录
     $file_dir = UPLOAD_DIR . IMG_DIR . ceil($userinfo['id'] / NUM_IMG) . "/";
     //文件路径
     $file_path = $file_dir . $file_name;
     if (!hg_mkdir($file_dir)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     if (!copy($uploadedfile, $file_path)) {
         $this->errorOutput(UPLOAD_ERR_NO_FILE);
     }
     $img = new GDImage($file_path, $file_path, '');
     $info = array();
     foreach ($size as $key => $value) {
         $new_name = $value['t'] . $file_name;
         $save_file_path = $file_dir . $new_name;
         $img->init_setting($file_path, $save_file_path, '');
         if ($key == "larger") {
             $img->maxWidth = $width > $value['size'] ? $value['size'] : $width;
             $img->maxHeight = $height * ($img->maxWidth / $width);
             $img->makeThumb(1, false, true);
         } else {
             if ($width > $height) {
                 $img->maxWidth = $width > $value['size'] ? $value['size'] : $width;
                 $img->maxHeight = $height * ($img->maxWidth / $width);
             } else {
                 $img->maxHeight = $height > $value['size'] ? $value['size'] : $height;
                 $img->maxWidth = $width * ($img->maxHeight / $height);
             }
             $img->makeThumb(3);
         }
         $info[$key] = UPLOAD_URL . IMG_DIR . ceil($userinfo['id'] / NUM_IMG) . "/" . $new_name;
         if (defined('WATER_MARK_DONE') && WATER_MARK_DONE == true) {
             $img->create_watermark($save_file_path, $type, 4, WATER_MARK_IMG);
         }
     }
     $ip = hg_getip();
     $create_at = time();
     $sql = "INSERT " . DB_PREFIX . "media(status_id,dir,url,ip,create_at) VALUES(0,'" . IMG_DIR . ceil($userinfo['id'] / NUM_IMG) . "/" . "','" . $file_name . "','" . $ip . "'," . $create_at . ")";
     $this->db->query($sql);
     $id = $this->db->insert_id();
     $info['id'] = $id;
     $info['url'] = $file_name;
     $info['ip'] = $ip;
     $info['create_at'] = $create_at;
     $info['type'] = 0;
     return $info;
 }