Example #1
0
 /**
  * Method to apply a background color to an image resource.
  *
  * @param   array  $options  An array of options for the filter.
  *                           color  Background matte color
  *
  * @return  void
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  * @deprecated  5.0  Use Joomla\Image\Filter\Backgroundfill::execute() instead
  */
 public function execute(array $options = array())
 {
     // Validate that the color value exists and is an integer.
     if (!isset($options['color'])) {
         throw new InvalidArgumentException('No color value was given. Expected string or array.');
     }
     $colorCode = !empty($options['color']) ? $options['color'] : null;
     // Get resource dimensions
     $width = imagesX($this->handle);
     $height = imagesY($this->handle);
     // Sanitize color
     $rgba = $this->sanitizeColor($colorCode);
     // Enforce alpha on source image
     if (imageIsTrueColor($this->handle)) {
         imageAlphaBlending($this->handle, false);
         imageSaveAlpha($this->handle, true);
     }
     // Create background
     $bg = imageCreateTruecolor($width, $height);
     imageSaveAlpha($bg, empty($rgba['alpha']));
     // Allocate background color.
     $color = imageColorAllocateAlpha($bg, $rgba['red'], $rgba['green'], $rgba['blue'], $rgba['alpha']);
     // Fill background
     imageFill($bg, 0, 0, $color);
     // Apply image over background
     imageCopy($bg, $this->handle, 0, 0, 0, 0, $width, $height);
     // Move flattened result onto curent handle.
     // If handle was palette-based, it'll stay like that.
     imageCopy($this->handle, $bg, 0, 0, 0, 0, $width, $height);
     // Free up memory
     imageDestroy($bg);
     return;
 }
Example #2
0
 /**
  * function addWatermark
  *
  * @param string $imageFile
  * @param string $destinationFile
  */
 function addWatermark($imageFile, $destinationFile = true)
 {
     if ($destinationFile) {
         $destinationFile = $imageFile;
     }
     $watermark = @imagecreatefrompng($this->watermarkFile) or exit('Cannot open the watermark file.');
     imageAlphaBlending($watermark, false);
     imageSaveAlpha($watermark, true);
     $image_string = @file_get_contents($imageFile) or exit('Cannot open image file.');
     $image = @imagecreatefromstring($image_string) or exit('Not a valid image format.');
     $imageWidth = imageSX($image);
     $imageHeight = imageSY($image);
     $watermarkWidth = imageSX($watermark);
     $watermarkHeight = imageSY($watermark);
     if ($this->position == 'center') {
         $coordinate_X = ($imageWidth - $watermarkWidth) / 2;
         $coordinate_Y = ($imageHeight - $watermarkHeight) / 2;
     } else {
         $coordinate_X = $imageWidth - 5 - $watermarkWidth;
         $coordinate_Y = $imageHeight - 5 - $watermarkHeight;
     }
     imagecopy($image, $watermark, $coordinate_X, $coordinate_Y, 0, 0, $watermarkWidth, $watermarkHeight);
     if ($this->imageType == 'jpg') {
         imagejpeg($image, $destinationFile, 100);
     } elseif ($this->imageType == 'gif') {
         imagegif($image, $destinationFile);
     } elseif ($this->imageType == 'png') {
         imagepng($image, $destinationFile, 100);
     }
     imagedestroy($image);
     imagedestroy($watermark);
 }
Example #3
0
 public function __construct($data)
 {
     $this->data = $data;
     $size = array_key_exists('global', $this->data) ? 'l' : 's';
     $text = !array_key_exists('text', $this->data) || strlen($this->data['text']) > 2 ? '??' : $this->data['text'];
     $font = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . '/img/base/xkcd.ttf';
     $fg = $this->hex2rgb($this->colorGiven('fg') ? $this->data['fg'] : '000');
     $bg = $this->hex2rgb($this->colorGiven('bg') ? $this->data['bg'] : '0ff');
     $this->image = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . '/img/base/fill_' . $size . '.png');
     imageAlphaBlending($this->image, true);
     imageSaveAlpha($this->image, true);
     $fc = imagecolorallocate($this->image, $fg['r'], $fg['g'], $fg['b']);
     $c = imagecolorallocate($this->image, $bg['r'], $bg['g'], $bg['b']);
     imagefill($this->image, imagesx($this->image) / 2, imagesy($this->image) / 2, $c);
     $outline = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'] . '/img/base/outline_' . $size . '.png');
     imageAlphaBlending($outline, true);
     imageSaveAlpha($outline, true);
     imagecopy($this->image, $outline, 0, 0, 0, 0, imagesx($outline), imagesy($this->image));
     if ($size === 'l') {
         imagettftext($this->image, 12, 0, 3, 25, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', 'global');
         $bounds = imagettfbbox(20, 0, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
         imagettftext($this->image, 20, 0, (imagesx($this->image) - $bounds[4] - $bounds[0]) / 2, 50, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
     } else {
         $bounds = imagettfbbox(15, 0, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
         imagettftext($this->image, 15, 0, (imagesx($this->image) - $bounds[4] - $bounds[0]) / 2, 22, $fc, $_SERVER['DOCUMENT_ROOT'] . '/img/base/xkcd.ttf', $text);
     }
 }
function hacknrollify($picfilename)
{
    $logofilename = "logo.png";
    $logoPicPath = "logopics/" . $logofilename;
    $originalPicPath = "originalpics/" . $picfilename;
    $editedfilename = "hnr_" . $picfilename;
    $editedPicPath = "editedpics/" . $editedfilename;
    // read the original image from file
    $profilepic = imagecreatefromjpeg($originalPicPath);
    $profilepicWidth = imagesx($profilepic);
    $profilepicHeight = imagesy($profilepic);
    // create the black image overlay
    $blackoverlay = imagecreate($profilepicWidth, $profilepicHeight);
    imagecolorallocate($blackoverlay, 0, 0, 0);
    // then merge the black and profilepic
    imagecopymerge($profilepic, $blackoverlay, 0, 0, 0, 0, $profilepicWidth, $profilepicHeight, 50);
    imagedestroy($blackoverlay);
    // merge the resized logo
    $logo = resizeImage($logoPicPath, $profilepicWidth - 80, 999999);
    imageAlphaBlending($logo, false);
    imageSaveAlpha($logo, true);
    $logoWidth = imagesx($logo);
    $logoHeight = imagesy($logo);
    $verticalOffset = $profilepicHeight / 2 - $logoHeight / 2;
    $horizontalOffset = 40;
    imagecopyresampled($profilepic, $logo, $horizontalOffset, $verticalOffset, 0, 0, $logoWidth, $logoHeight, $logoWidth, $logoHeight);
    $mergeSuccess = imagejpeg($profilepic, $editedPicPath);
    if (!$mergeSuccess) {
        echo "Image merge failed!";
    }
    imagedestroy($profilepic);
    imagedestroy($logo);
    return $editedPicPath;
}
Example #5
0
 /**
  * Create image resource from image file and alocate required memory
  * @param $imageFile
  * @return resource
  * @throws \Ip\Exception\Repository\Transform
  */
 protected function createImageImage($imageFile)
 {
     $this->getMemoryNeeded($imageFile);
     $mime = $this->getMimeType($imageFile);
     switch ($mime) {
         case IMAGETYPE_JPEG:
         case IMAGETYPE_JPEG2000:
             $originalSetting = ini_set('gd.jpeg_ignore_warning', 1);
             $image = imagecreatefromjpeg($imageFile);
             if ($originalSetting !== false) {
                 ini_set('gd.jpeg_ignore_warning', $originalSetting);
             }
             break;
         case IMAGETYPE_GIF:
             $image = imagecreatefromgif($imageFile);
             imageAlphaBlending($image, false);
             imageSaveAlpha($image, true);
             break;
         case IMAGETYPE_PNG:
             $image = imagecreatefrompng($imageFile);
             imageAlphaBlending($image, false);
             imageSaveAlpha($image, true);
             break;
         default:
             throw new \Ip\Exception\Repository\Transform("Incompatible type. Type detected: " . esc($mime), array('mime' => $mime));
     }
     return $image;
 }
Example #6
0
 static function imgresize($photo_src, $width, $name)
 {
     $parametr = getimagesize($photo_src);
     list($width_orig, $height_orig) = getimagesize($photo_src);
     $ratio_orig = $width_orig / $height_orig;
     $new_width = $width;
     $new_height = $width / $ratio_orig;
     $newpic = imagecreatetruecolor($new_width, $new_height);
     imageAlphaBlending($newpic, false);
     imageSaveAlpha($newpic, true);
     switch ($parametr[2]) {
         case 1:
             $image = imagecreatefromgif($photo_src);
             break;
         case 2:
             $image = imagecreatefromjpeg($photo_src);
             break;
         case 3:
             $image = imagecreatefrompng($photo_src);
             break;
     }
     imagecopyresampled($newpic, $image, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
     imagepng($newpic, $name);
     return true;
 }
Example #7
0
 /**
  * Метод для изменения размера изображения.
  * @link URL Оригинал(Пример1) http://www.php.su/articles/?cat=graph&page=014
  */
 public function imageResize()
 {
     foreach ($this->data as $i => $param) {
         $descriptor = $param['descriptor'];
         $tmpImg = imagecreatetruecolor(20, 20);
         imageAlphaBlending($tmpImg, false);
         imageSaveAlpha($tmpImg, true);
         imagecopyresampled($tmpImg, $descriptor, 0, 0, 0, 0, 20, 20, $param['width'], $param['height']);
         switch ($param['type']) {
             case 'jpg':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagejpeg($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
             case 'jpeg':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagejpeg($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
             case 'png':
                 $this->data[$i]['width'] = 20;
                 $this->data[$i]['height'] = 20;
                 imagepng($tmpImg, $param['source']);
                 imagedestroy($tmpImg);
                 break;
         }
     }
 }
Example #8
0
 public function resize($maxW = null, $maxH = null, $canEnlarge = false)
 {
     $src = $this->_rawImage;
     if ($maxW === null && $maxH === null) {
         return $src;
     }
     if (imageistruecolor($src)) {
         imageAlphaBlending($src, true);
         imageSaveAlpha($src, true);
     }
     $srcW = imagesx($src);
     $srcH = imagesy($src);
     $width = $maxW && ($canEnlarge || $maxW <= $srcW) ? $maxW : $srcW;
     $height = $maxH && ($canEnlarge || $maxH <= $srcW) ? $maxH : $srcH;
     $ratio_orig = $srcW / $srcH;
     if ($width / $height > $ratio_orig) {
         $width = $height * $ratio_orig;
     } else {
         $height = $width / $ratio_orig;
     }
     $maxW = $maxW ? $maxW : $width;
     $maxH = $maxH ? $maxH : $height;
     $img = imagecreatetruecolor($maxW, $maxH);
     $trans_colour = imagecolorallocatealpha($img, 0, 0, 0, 127);
     imagefill($img, 0, 0, $trans_colour);
     $offsetX = ($maxW - $width) / 2;
     $offsetY = ($maxH - $height) / 2;
     imagecopyresampled($img, $src, $offsetX, $offsetY, 0, 0, $width, $height, $srcW, $srcH);
     imagealphablending($img, true);
     imagesavealpha($img, true);
     return $img;
 }
 public function loadImg($file)
 {
     if (!file_exists($file)) {
         //echo("File not found in loadImg().");
         return false;
     }
     $this->imageSize = getimagesize($file);
     if (!defined("IMAGETYPE_JPG")) {
         define("IMAGETYPE_JPG", IMAGETYPE_JPEG);
     }
     switch ($this->imageSize[2]) {
         case IMAGETYPE_JPG:
             $this->img = imagecreatefromjpeg($file);
             $this->file = $file;
             return true;
         case IMAGETYPE_PNG:
             $this->img = imagecreatefrompng($file);
             imageAlphaBlending($this->img, false);
             imageSaveAlpha($this->img, true);
             $this->file = $file;
             return true;
         case IMAGETYPE_GIF:
             $this->img = imagecreatefromgif($file);
             $this->file = $file;
             break;
         case IMAGETYPE_BMP:
             $this->img = ImageCreateFromBMP($file);
             $this->file = $file;
         default:
             //coreIMG::trace("Unknown file format in loadImg().");
             return false;
     }
 }
Example #10
0
 public function resizeImage($newWidth, $originalFile)
 {
     $allowGif = Configure::read('allowGif');
     if (!$allowGif) {
         $info = getimagesize($originalFile);
         $mime = $info['mime'];
         switch ($mime) {
             case 'image/jpeg':
                 $image_create_func = 'imagecreatefromjpeg';
                 $image_save_func = 'imagejpeg';
                 $new_image_ext = 'jpg';
                 break;
             case 'image/png':
                 $image_create_func = 'imagecreatefrompng';
                 $image_save_func = 'imagepng';
                 $new_image_ext = 'png';
                 break;
             case 'image/gif':
                 if (!$allowGif) {
                     $image_create_func = 'imagecreatefromgif';
                     $image_save_func = 'imagegif';
                     $new_image_ext = 'gif';
                 }
                 break;
             default:
                 //throw Exception('Unknown image type.');
         }
         if (isset($image_save_func) && function_exists('imap_open')) {
             $img = $image_create_func($originalFile);
             list($width, $height) = getimagesize($originalFile);
             $newHeight = $height / $width * $newWidth;
             $tmp = imagecreatetruecolor($newWidth, $newHeight);
             $targetFile = $originalFile;
             imageAlphaBlending($tmp, false);
             imageSaveAlpha($tmp, true);
             imagecopyresampled($tmp, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
             if (file_exists($targetFile)) {
                 unlink($targetFile);
             }
             ob_start();
             //Start output buffer.
             $image_save_func($tmp);
             //This will normally output the image, but because of ob_start(), it won't.
             $contents = ob_get_contents();
             //Instead, output above is saved to $contents
             ob_end_clean();
             //End the output buffer.
         } else {
             $contents = null;
         }
     }
     //$image_save_func($tmp, "$targetFile.$new_image_ext");
     return $contents;
 }
 public function writeWatermarkInfo(&$sourcefileId, $thumbnailMode, CacheFile $cacheFile)
 {
     if (!$this->config->isUsedWatermark() || $thumbnailMode) {
         return;
     }
     static $disable_alpha_warning;
     $watermarkfile = $this->config->getWatermarkFile();
     $align = $this->config->getWatermarkLeft();
     $valign = $this->config->getWatermarkTop();
     if ($this->config->getWatermarkTransparencyType() == 'alpha') {
         $transcolor = FALSE;
     } else {
         $transcolor = $this->config->getWatermarkTransparentColor();
     }
     $transparency = $this->config->getWatermarkTransparency();
     try {
         $watermarkfile_id = $this->loadWatermarkFile($watermarkfile);
     } catch (Exception $e) {
         return false;
     }
     @imageAlphaBlending($watermarkfile_id, false);
     $result = @imageSaveAlpha($watermarkfile_id, true);
     if (!$result) {
         if (!$disable_alpha_warning) {
             $msg = "Watermark problem: your server does not support alpha blending (requires GD 2.0.1+)";
             JLog::add($msg, JLog::WARNING);
         }
         $disable_alpha_warning = true;
         imagedestroy($watermarkfile_id);
         return false;
     }
     $offset_w = $cacheFile->offsetX();
     $offset_h = $cacheFile->offsetY();
     $w = $cacheFile->displayWidth();
     $h = $cacheFile->displayHeight();
     $watermarkfileWidth = imageSX($watermarkfile_id);
     $watermarkfileHeight = imageSY($watermarkfile_id);
     $watermarkOffsetX = $this->calcXOffsetForWatermark($align, $watermarkfileWidth, $offset_w, $w);
     $watermarkOffsetY = $this->calcYOffsetForWatermark($valign, $watermarkfileHeight, $offset_h, $h);
     $fileType = strtolower(pathinfo($watermarkfile, PATHINFO_EXTENSION));
     $sourcefileId = $this->upsampleImageIfNecessary($fileType, $sourcefileId);
     if ($transcolor !== false) {
         $transcolAsInt = intval(str_replace('#', '', $transcolor), 16);
         imagecolortransparent($watermarkfile_id, $transcolAsInt);
         // use transparent color
         imagecopymerge($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight, $transparency);
     } else {
         imagecopy($sourcefileId, $watermarkfile_id, $watermarkOffsetX, $watermarkOffsetY, 0, 0, $watermarkfileWidth, $watermarkfileHeight);
         // True
         // alphablend
     }
     imagedestroy($watermarkfile_id);
     return true;
 }
Example #12
0
 private function get_file($type)
 {
     include_once 'Cache_Lite/Lite.php';
     $db = Input::getPath()->part(5);
     $baseLayer = Input::get("baselayer");
     $layers = Input::get("layers");
     $center = Input::get("center");
     $zoom = Input::get("zoom");
     $size = Input::get("size");
     $sizeArr = explode("x", Input::get("size"));
     $bbox = Input::get("bbox");
     $sql = Input::get("sql");
     $id = $db . "_" . $baseLayer . "_" . $layers . "_" . $center . "_" . $zoom . "_" . $size . "_" . $bbox . "_" . $sql;
     $lifetime = Input::get('lifetime') ?: 0;
     $options = array('cacheDir' => \app\conf\App::$param['path'] . "app/tmp/", 'lifeTime' => $lifetime);
     $Cache_Lite = new \Cache_Lite($options);
     if ($data = $Cache_Lite->get($id)) {
         //echo "Cached";
     } else {
         ob_start();
         $fileName = md5(time() . rand(10000, 99999) . microtime());
         $file = \app\conf\App::$param["path"] . "/app/tmp/_" . $fileName . "." . $type;
         $cmd = "wkhtmltoimage " . "--height {$sizeArr[1]} --disable-smart-width --width {$sizeArr[0]} --quality 90 --javascript-delay 1000 " . "\"" . "http://127.0.0.1" . "/api/v1/staticmap/html/{$db}?baselayer={$baseLayer}&layers={$layers}&center={$center}&zoom={$zoom}&size={$size}&bbox={$bbox}&sql={$sql}\" " . $file;
         //die($cmd);
         exec($cmd);
         switch ($type) {
             case "png":
                 $res = imagecreatefrompng($file);
                 break;
             case "jpg":
                 $res = imagecreatefromjpeg($file);
                 break;
         }
         if (!$res) {
             $response['success'] = false;
             $response['message'] = "Could not create image";
             $response['code'] = 406;
             header("HTTP/1.0 {$response['code']} " . \app\inc\Util::httpCodeText($response['code']));
             echo \app\inc\Response::toJson($response);
             exit;
         }
         header('Content-type: image/png');
         imageAlphaBlending($res, true);
         imageSaveAlpha($res, true);
         imagepng($res);
         // Cache script
         $data = ob_get_contents();
         $Cache_Lite->save($data, $id);
         ob_get_clean();
     }
     header("Content-type: image/png");
     echo $data;
     exit;
 }
Example #13
0
function LoadPNG($imgname)
{
    /* Attempt to open */
    $im = @imagecreatefrompng($imgname);
    /* See if it failed */
    if (!$im) {
        $im = @imagecreatefrompng("/usr/local/share/pbi-manager/icons/default.png");
    }
    imageAlphaBlending($im, true);
    imageSaveAlpha($im, true);
    return $im;
}
Example #14
0
 /**
  * Load image
  *
  * @param string filename
  *
  * @return mixed none or a PEAR error object on error
  * @see PEAR::isError()
  */
 function load($image)
 {
     $this->uid = md5($_SERVER['REMOTE_ADDR']);
     $this->image = $image;
     $this->_get_image_details($image);
     $functionName = 'ImageCreateFrom' . $this->type;
     if (function_exists($functionName)) {
         $this->imageHandle = $functionName($this->image);
         if ($this->type == 'png') {
             imageAlphaBlending($this->imageHandle, false);
             imageSaveAlpha($this->imageHandle, true);
         }
     }
 }
Example #15
0
 private function mergerImg($imgs)
 {
     list($max_width, $max_height) = getimagesize($imgs['dst']);
     $dest = imagecreatefromjpeg($imgs['dst']);
     $src = imageCreateFromPng($imgs['src']);
     imageAlphaBlending($dest, true);
     imageSaveAlpha($dest, true);
     self::imagecopymerge_alpha($dest, $src, 0, 0, 0, 0, $max_width, $max_height, 100);
     $filename = $this->getFileName('jpg');
     // header("Content-type: image/jpeg");
     imagejpeg($dest, $filename, 80);
     imagedestroy($src);
     imagedestroy($dest);
     return $filename;
 }
function do_icon($icon, $text, $color)
{
    $im = imagecreatefrompng($icon);
    imageAlphaBlending($im, true);
    imageSaveAlpha($im, true);
    $len = strlen($text);
    $p1 = $len <= 2 ? 1 : 2;
    $p2 = $len <= 2 ? 3 : 2;
    $px = (imagesx($im) - 7 * $len) / 2 + $p1;
    $font = 'arial.ttf';
    $contrast = $color ? imagecolorallocate($im, 255, 255, 255) : imagecolorallocate($im, 0, 0, 0);
    // white on dark?
    imagestring($im, $p2, $px, 3, $text, $contrast);
    // imagestring  ( $image, $font, $x, $y, $string, $color)
    imagepng($im);
    imagedestroy($im);
}
Example #17
0
 public function get_tms()
 {
     $parts = explode("/", $_SERVER['REQUEST_URI']);
     $url = "http://127.0.0.1/cgi/tilecache.py/{$parts[3]}/{$parts[4]}/{$parts[5]}/{$parts[6]}/{$parts[7]}?cfg={$this->db}";
     $res = imagecreatefrompng($url);
     if (!$res) {
         $response['success'] = false;
         $response['message'] = "Could create tile";
         $response['code'] = 406;
         header("HTTP/1.0 {$response['code']} " . \app\inc\Util::httpCodeText($response['code']));
         echo \app\inc\Response::toJson($response);
         exit;
     }
     header('Content-type: image/png');
     imageAlphaBlending($res, true);
     imageSaveAlpha($res, true);
     imagepng($res);
     exit;
 }
Example #18
0
function create_secimage()
{
    global $image;
    $ret = array();
    $width = 250;
    $height = 100;
    $image = imagecreatetruecolor($width, $height);
    imageAlphaBlending($image, true);
    imageSaveAlpha($image, true);
    $color_1 = imagecolorallocate($image, 150, 150, 250);
    $color_2 = imagecolorallocate($image, 80, 80, 80);
    imageblend(0, 0, FIXED_GFX_PATH . "sec-gfx/bg.png", $image);
    /* 25/06/10 - AC: Disabled races logos for readability
    	$thumbs=array(FIXED_GFX_PATH."sec-gfx/cardassian.png",
    		FIXED_GFX_PATH."sec-gfx/dominion.png",
    		FIXED_GFX_PATH."sec-gfx/federation.png",
    		FIXED_GFX_PATH."sec-gfx/ferengi.png",
    	FIXED_GFX_PATH."sec-gfx/klingon.png",
    		FIXED_GFX_PATH."sec-gfx/romlulan.png");
    	shuffle($thumbs);
    
    	$t=0;
    	foreach ($thumbs as $value) 
    	{
    		imageblend($t*50,rand(0,$height-60),$value,$image);
    		$t++;
    	}*/
    for ($t = 0; $t < 6; $t++) {
        $color = imagecolorallocate($image, rand(40, 255), rand(40, 255), rand(40, 255));
        circle(rand(25, $width - 25), rand(25, $height - 25), 50, $color);
    }
    $color = imagecolorallocate($image, rand(40, 255), rand(40, 255), rand(40, 255));
    $pos[0] = rand(25, $width - 25);
    $pos[1] = rand(25, $height - 25);
    circle_sectioned($pos[0], $pos[1], 50, $color);
    $ret['center'] = implode(":", $pos);
    $md5 = md5(rand(0, 1000000));
    $ret['filename'] = 'tmpsec/sec' . $md5 . '.jpg';
    imagejpeg($image, $ret['filename'], 20);
    return $ret;
}
Example #19
0
 public function crop($x0 = '', $y0 = '', $size, $width)
 {
     if (empty($size) || empty($width)) {
         throw new InvalidParamsException();
     }
     if (empty($x0) && empty($y0)) {
         $x0 = 0;
         $y0 = 0;
     }
     $height = $width * $this->height / $this->width;
     $x = $x0 * $this->width / $width;
     $y = $y0 * $this->height / $height;
     $newSize = $size * $this->height / $height;
     $newimageresource = imagecreatetruecolor(150, 150);
     imageAlphaBlending($newimageresource, false);
     imageSaveAlpha($newimageresource, true);
     imagecopyresampled($newimageresource, $this->getResource(), 0, 0, $x, $y, 150, 150, $newSize, $newSize);
     switch ($this->format) {
         case self::JPEG:
             $aname = "a" . time() . ".jpg";
             if (!imagejpeg($newimageresource, "avatars/" . $aname, 100)) {
                 throw new FileNotSaveException();
             }
             break;
         case self::GIF:
             $aname = "a" . time() . ".gif";
             if (!imagegif($newimageresource, "avatars/" . $aname)) {
                 throw new FileNotSaveException();
             }
             break;
         case self::PNG:
             $aname = "a" . time() . ".png";
             if (!imagepng($newimageresource, "avatars/" . $aname, 9)) {
                 throw new FileNotSaveException();
             }
             break;
     }
     return $aname;
 }
Example #20
0
 public function create(UserInterface $user, $picture, $overlay)
 {
     $width = 640;
     $height = 480;
     $dest_image = imagecreatetruecolor($width, $height);
     $filename = uniqid('', true) . '.png';
     $encodedData = str_replace(' ', '+', $overlay);
     $frame = imagecreatefrompng($encodedData);
     imageAlphaBlending($frame, true);
     imageSaveAlpha($frame, true);
     $encodedData = str_replace(' ', '+', $picture);
     $picture = imagecreatefrompng($encodedData);
     imageAlphaBlending($picture, true);
     imageSaveAlpha($picture, true);
     imagecopy($dest_image, $picture, 0, 0, 0, 0, $width, $height);
     imagecopy($dest_image, $frame, 0, 0, 0, 0, $width, $height);
     imagepng($dest_image, UPLOADS . $filename);
     imagedestroy($dest_image);
     $pic = new Picture();
     $pic->setUserId($user->getId())->setPath('/uploads/' . $filename)->setRealPath(UPLOADS . $filename);
     return $pic;
 }
function resizeImage($filename, $max_width, $max_height)
{
    list($orig_width, $orig_height) = getimagesize($filename);
    $width = $orig_width;
    $height = $orig_height;
    # taller
    if ($height > $max_height) {
        $width = $max_height / $height * $width;
        $height = $max_height;
    }
    # wider
    if ($width > $max_width) {
        $height = $max_width / $width * $height;
        $width = $max_width;
    }
    $image_p = imagecreatetruecolor($width, $height);
    imageAlphaBlending($image_p, false);
    imageSaveAlpha($image_p, true);
    $image = imagecreatefrompng($filename);
    imageAlphaBlending($image, false);
    imageSaveAlpha($image, true);
    imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $orig_width, $orig_height);
    return $image_p;
}
Example #22
0
 public function purgeAction($lines = 90)
 {
     $time = microtime(true);
     $this->purge_history($lines, false);
     $this->purge_order($lines, false);
     $delay = microtime(true) - $time;
     if ($delay < 10) {
         $color = 'green';
     } elseif ($delay < 30) {
         $color = 'purple';
     } else {
         $color = 'red';
     }
     /* Tente d'ouvrir l'image */
     $request = Request::createFromGlobals();
     $images = $root = $this->get('kernel')->getRootDir();
     header('Content-Type: image/png');
     $img = imagecreatefrompng('../web/arii/images/silk/bullet_' . $color . '.png');
     imageAlphaBlending($img, true);
     imageSaveAlpha($img, true);
     imagepng($img);
     imagedestroy($img);
     exit;
 }
Example #23
0
 function _adjustTransparency(&$Source, &$Destination)
 {
     if ($this->_isTransparent($Source)) {
         $rgba = imageColorsForIndex($Source, imageColorTransparent($Source));
         $color = imageColorAllocate($Destination, $rgba['red'], $rgba['green'], $rgba['blue']);
         imageColorTransparent($Destination, $color);
         imageFill($Destination, 0, 0, $color);
     } else {
         if ($this->_format == 'png') {
             imageAlphaBlending($Destination, false);
             imageSaveAlpha($Destination, true);
         } elseif ($this->_format != 'gif') {
             $white = imageColorAllocate($Destination, 255, 255, 255);
             imageFill($Destination, 0, 0, $white);
         }
     }
 }
Example #24
0
 /**
  * Write the image after being processed
  *
  * @param Asido_TMP &$tmp
  * @return boolean
  * @access protected
  */
 function __write(&$tmp)
 {
     // try to guess format from extension
     //
     if (!$tmp->save) {
         $p = pathinfo($tmp->target_filename);
         ($tmp->save = $this->__mime_metaphone[metaphone($p['extension'])]) || ($tmp->save = $this->__mime_soundex[soundex($p['extension'])]);
     }
     $result = false;
     $imgContent = null;
     switch ($tmp->save) {
         case 'image/gif':
             imageTrueColorToPalette($tmp->target, true, 256);
             ob_start();
             $result = @imageGIF($tmp->target);
             $imgContent = ob_get_clean();
             break;
         case 'image/jpeg':
             ob_start();
             $result = @imageJPEG($tmp->target, null, ASIDO_GD_JPEG_QUALITY);
             $imgContent = ob_get_clean();
             break;
         case 'image/wbmp':
             ob_start();
             $result = @imageWBMP($tmp->target);
             $imgContent = ob_get_clean();
             break;
         default:
         case 'image/png':
             imageSaveAlpha($tmp->target, true);
             imageAlphaBlending($tmp->target, false);
             ob_start();
             $result = @imagePNG($tmp->target, null, ASIDO_GD_PNG_QUALITY);
             $imgContent = ob_get_clean();
             break;
     }
     if ($result) {
         jimport('joomla.filesystem.file');
         JFile::write($tmp->target_filename, $imgContent);
     }
     @$this->__destroy_source($tmp);
     @$this->__destroy_target($tmp);
     return $result;
 }
 /**
  * Genereren van een minimap
  */
 function admin_generateminimap($map_id = null)
 {
     $someMap = $this->Map->find('first', array('conditions' => array('Map.id' => $map_id)));
     if (empty($someMap)) {
         $this->redirect('/admin/maps');
     }
     App::import('Vendor', 'Image', array('file' => 'image.php'));
     $Image = new Image();
     $mapAreas = $this->Map->getMap(null, $someMap['Map']['id']);
     // Posities etc berekenen
     $highest_x = 0;
     $highest_y = 0;
     $areas = array();
     foreach ($mapAreas as $area) {
         if ($highest_x < $area['Area']['x']) {
             $highest_x = $area['Area']['x'];
         }
         if ($highest_y < $area['Area']['y']) {
             $highest_y = $area['Area']['y'];
         }
         $areas[$area['Area']['x']][$area['Area']['y']] = $area;
     }
     $width_org = Configure::read('Game.tile.width') * $highest_x;
     $height_org = Configure::read('Game.tile.height') * $highest_y;
     // Originele grootte
     $im_org = imagecreatetruecolor($width_org, $height_org);
     imageAlphaBlending($im_org, true);
     imageSaveAlpha($im_org, true);
     // Zwarte achtergrond
     //$black = imagecolorallocate($im_org, 0,0,0);
     // Doorlopen van de x,y areas
     for ($i = 1; $i <= $highest_x; $i++) {
         for ($j = 1; $j <= $highest_y; $j++) {
             // tile plakken op het origineel
             $tile_x = ($i - 1) * Configure::read('Game.tile.width');
             $tile_y = ($j - 1) * Configure::read('Game.tile.height');
             if ($tile = @imagecreatefrompng(WWW_ROOT . 'img' . DS . 'game' . DS . 'tiles' . DS . $areas[$i][$j]['Tile']['image'])) {
                 imageAlphaBlending($tile, true);
                 imageSaveAlpha($tile, true);
                 // bool imagecopymerge  (  resource $dst_im  ,  resource $src_im  ,  int $dst_x  ,  int $dst_y  ,  int $src_x  ,  int $src_y  ,  int $src_w  ,  int $src_h  ,  int $pct  )
                 imagecopymerge($im_org, $tile, $tile_x, $tile_y, 0, 0, Configure::read('Game.tile.width'), Configure::read('Game.tile.height'), 100);
                 imagedestroy($tile);
             }
             // Obstacles...
             foreach ($areas[$i][$j]['Obstacle'] as $obstacle) {
                 if ($im_obstacle = @imagecreatefrompng(WWW_ROOT . 'img' . DS . 'game' . DS . 'obstacles' . DS . $obstacle['image'])) {
                     imageAlphaBlending($im_obstacle, true);
                     imageSaveAlpha($im_obstacle, true);
                     list($o_width, $o_height) = getimagesize(WWW_ROOT . 'img' . DS . 'game' . DS . 'obstacles' . DS . $obstacle['image']);
                     $obstacle_x = $tile_x + $obstacle['AreasObstacle']['x'];
                     $obstacle_y = $tile_y + $obstacle['AreasObstacle']['y'];
                     // bool imagecopymerge  (  resource $dst_im  ,  resource $src_im  ,  int $dst_x  ,  int $dst_y  ,  int $src_x  ,  int $src_y  ,  int $src_w  ,  int $src_h  ,  int $pct  )
                     $Image->imagecopymerge_alpha($im_org, $im_obstacle, $obstacle_x, $obstacle_y, 0, 0, $o_width, $o_height);
                     imagedestroy($im_obstacle);
                 }
             }
         }
     }
     if (!empty($someMap['Map']['image'])) {
         // Oude verwijderen
         @unlink(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'small' . DS . $someMap['Map']['image']);
         @unlink(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'big' . DS . $someMap['Map']['image']);
         @unlink(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'medium' . DS . $someMap['Map']['image']);
     }
     $imageName = md5(uniqid(mt_rand(), true)) . '.png';
     if (imagepng($im_org, WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'original' . DS . $imageName)) {
         // Copies maken
         $Image->resize(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'small' . DS . $imageName, 100, 100);
         $Image->resize(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'medium' . DS . $imageName, 123, 123);
         $Image->resize(WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'original' . DS . $imageName, WWW_ROOT . 'img' . DS . 'game' . DS . 'maps' . DS . 'big' . DS . $imageName, 250, 250);
     }
     $someMap['Map']['image'] = $imageName;
     $this->Map->save($someMap);
     $this->redirect('/admin/maps');
 }
Example #26
0
    /**
     * 为图片增加水印
     *
     * @access      public
     * @param       string      filename            原始图片文件名,包含完整路径
     * @param       string      target_file         需要加水印的图片文件名,包含完整路径。如果为空则覆盖源文件
     * @param       string      $watermark          水印完整路径
     * @param       int         $watermark_place    水印位置代码
     * @return      mix         如果成功则返回文件路径,否则返回false
     */
    function add_watermark($filename, $target_file='', $watermark='', $watermark_place='', $watermark_alpha = 0.65)
    {
        // 是否安装了GD
        $gd = $this->gd_version();
        if ($gd == 0)
        {
            $this->error_msg = $GLOBALS['_LANG']['missing_gd'];
            $this->error_no  = ERR_NO_GD;

            return false;
        }

        // 文件是否存在
        if ((!file_exists($filename)) || (!is_file($filename)))
        {
            $this->error_msg  = sprintf($GLOBALS['_LANG']['missing_orgin_image'], $filename);
            $this->error_no   = ERR_IMAGE_NOT_EXISTS;

            return false;
        }

        /* 如果水印的位置为0,则返回原图 */
        if ($watermark_place == 0 || empty($watermark))
        {
            return str_replace(ROOT_PATH, '', str_replace('\\', '/', realpath($filename)));
        }

        if (!$this->validate_image($watermark))
        {
            /* 已经记录了错误信息 */
            return false;
        }

        // 获得水印文件以及源文件的信息
        $watermark_info     = @getimagesize($watermark);
        $watermark_handle   = $this->img_resource($watermark, $watermark_info[2]);

        if (!$watermark_handle)
        {
            $this->error_msg = sprintf($GLOBALS['_LANG']['create_watermark_res'], $this->type_maping[$watermark_info[2]]);
            $this->error_no  = ERR_INVALID_IMAGE;

            return false;
        }

        // 根据文件类型获得原始图片的操作句柄
        $source_info    = @getimagesize($filename);
        $source_handle  = $this->img_resource($filename, $source_info[2]);
        if (!$source_handle)
        {
            $this->error_msg = sprintf($GLOBALS['_LANG']['create_origin_image_res'], $this->type_maping[$source_info[2]]);
            $this->error_no = ERR_INVALID_IMAGE;

            return false;
        }

        // 根据系统设置获得水印的位置
        switch ($watermark_place)
        {
            case '1':
                $x = 0;
                $y = 0;
                break;
            case '2':
                $x = $source_info[0] - $watermark_info[0];
                $y = 0;
                break;
            case '4':
                $x = 0;
                $y = $source_info[1] - $watermark_info[1];
                break;
            case '5':
                $x = $source_info[0] - $watermark_info[0];
                $y = $source_info[1] - $watermark_info[1];
                break;
            default:
                $x = $source_info[0]/2 - $watermark_info[0]/2;
                $y = $source_info[1]/2 - $watermark_info[1]/2;
        }

        if (strpos(strtolower($watermark_info['mime']), 'png') !== false)
        {
            imageAlphaBlending($watermark_handle, true);
            imagecopy($source_handle, $watermark_handle, $x, $y, 0, 0,$watermark_info[0], $watermark_info[1]);
        }
        else
        {
            imagecopymerge($source_handle, $watermark_handle, $x, $y, 0, 0,$watermark_info[0], $watermark_info[1], $watermark_alpha);
        }
        $target = empty($target_file) ? $filename : $target_file;

        switch ($source_info[2] )
        {
            case 'image/gif':
            case 1:
                imagegif($source_handle,  $target);
                break;

            case 'image/pjpeg':
            case 'image/jpeg':
            case 2:
                imagejpeg($source_handle, $target);
                break;

            case 'image/x-png':
            case 'image/png':
            case 3:
                imagepng($source_handle,  $target);
                break;

            default:
                $this->error_msg = $GLOBALS['_LANG']['creating_failure'];
                $this->error_no = ERR_NO_GD;

                return false;
        }

        imagedestroy($source_handle);

        $path = realpath($target);
        if ($path)
        {
            return str_replace(ROOT_PATH, '', str_replace('\\', '/', $path));
        }
        else
        {
            $this->error_msg = $GLOBALS['_LANG']['writting_failure'];
            $this->error_no  = ERR_DIRECTORY_READONLY;

            return false;
        }
    }
function makeTrackImage($imagefile, $type = "png")
{
    if ($type == "png") {
        $ImageIn = imagecreatefrompng($imagefile);
    }
    if ($type == "jpg") {
        $ImageIn = imagecreatefromjpeg($imagefile);
    }
    $width = ImageSX($ImageIn);
    $height = ImageSY($ImageIn);
    //now create truecolor image and transfer
    $ImageOut = imagecreatetruecolor($width, $height);
    if ($type == "png") {
        //if not truecolor, convert png to truecolor png
        if (!imageistruecolor($ImageIn)) {
            imagealphablending($ImageOut, false);
            imagecopy($ImageOut, $ImageIn, 0, 0, 0, 0, $width, $height);
            imagesavealpha($ImageOut, true);
            $bgColor = imagecolorallocate($ImageIn, 255, 255, 255);
            ImageColorTransparent($ImageOut, $bgColor);
            imagefill($ImageOut, 0, 0, $bgColor);
            /*
            $original_transparency=-1;
            
            $Image_transparency = imagecolortransparent($ImageIn);
            $original_transparency=$Image_transparency;
            if ($Image_transparency >= 0) {
                //get the actual transparent color
                $rgb = imagecolorsforindex($ImageIn, $Image_transparency);
                $Image_transparency = ($rgb['red'] << 16) | ($rgb['green'] << 8) | $rgb['blue'];
                //change the transparent color to black, since transparent goes to black anyways (no way to remove transparency in GIF)
                imagecolortransparent($ImageIn, imagecolorallocate($ImageIn, 0, 0, 0));
            }
            */
            #imagealphablending($ImageIn, true);
            #imagealphablending($ImageOut, true);
            #imagesavealpha($ImageIn, true);
            #imagesavealpha($ImageOut, true);
            #1:
            #$bgColor = imagecolorallocate($ImageIn, 255,255,255);
            #ImageColorTransparent($ImageOut, $bgColor);
            #imagefill($ImageOut , 0,0 , $bgColor);
            #2:
            #$bgColor = imagecolorat($ImageIn,1,1);
            #imagecolortransparent($ImageOut, $bgColor);
            #3:
            #$trans_color = imagecolorallocatealpha($ImageIn, 0, 0, 0, 127);
            #ImageColorTransparent($ImageOut, $trans_color);
            #imagecopy($ImageOut, $ImageIn, 0, 0, 0, 0, $width, $height);
            #imagefill($ImageOut, 0, 0, $trans_color);
            //remake transparency (if there was transparency)
            /*
            if ($original_transparency >= 0) {
            	imagealphablending($ImageOut, false);
            	imagesavealpha($ImageOut, true);
            	for ($x = 0; $x < $w; $x++) {
            		for ($y = 0; $y < $h; $y++) {
            			if (imagecolorat($ImageOut, $x, $y) == $Image_transparency) {
                    		imagesetpixel($ImageOut, $x, $y, 127 << 24);
            			}//if
            		}//for
            	}//for
            	//And now $img is a true color image resource
            }// if orig trs
            */
        }
        //not truecolor
        //true color png
        if (imageistruecolor($ImageIn)) {
            imageAlphaBlending($ImageIn, true);
            imageSaveAlpha($ImageIn, true);
            $ImageOut = $ImageIn;
        }
        //truecolor
    }
    //type=png
    if ($type == "jpg") {
        $ImageOut = $ImageIn;
    }
    //jpg
    #imagedestroy($imageIn);
    return $ImageOut;
}
Example #28
0
 function Watermark_GD($type = 'forum')
 {
     if (!function_exists('imagecreatetruecolor')) {
         return -4;
     }
     $imagefunc =& $this->imagefunc;
     if ($this->param['watermarktype'][$type] != 'text') {
         if (!function_exists('imagecopy') || !function_exists('imagecreatefrompng') || !function_exists('imagecreatefromgif') || !function_exists('imagealphablending') || !function_exists('imagecopymerge')) {
             return -4;
         }
         $watermarkinfo = @getimagesize($this->param['watermarkfile'][$type]);
         if ($watermarkinfo === FALSE) {
             return -3;
         }
         $watermark_logo = $this->param['watermarktype'][$type] == 'png' ? @imageCreateFromPNG($this->param['watermarkfile'][$type]) : @imageCreateFromGIF($this->param['watermarkfile'][$type]);
         if (!$watermark_logo) {
             return 0;
         }
         list($logo_w, $logo_h) = $watermarkinfo;
     } else {
         if (!function_exists('imagettfbbox') || !function_exists('imagettftext') || !function_exists('imagecolorallocate')) {
             return -4;
         }
         if (!class_exists('Chinese')) {
             include libfile('class/chinese');
         }
         $watermarktextcvt = pack("H*", $this->param['watermarktext']['text'][$type]);
         $box = imagettfbbox($this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
         $logo_h = max($box[1], $box[3]) - min($box[5], $box[7]);
         $logo_w = max($box[2], $box[4]) - min($box[0], $box[6]);
         $ax = min($box[0], $box[6]) * -1;
         $ay = min($box[5], $box[7]) * -1;
     }
     $wmwidth = $this->imginfo['width'] - $logo_w;
     $wmheight = $this->imginfo['height'] - $logo_h;
     if ($wmwidth > 10 && $wmheight > 10 && !$this->imginfo['animated']) {
         switch ($this->param['watermarkstatus'][$type]) {
             case 1:
                 $x = 5;
                 $y = 5;
                 break;
             case 2:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = 5;
                 break;
             case 3:
                 $x = $this->imginfo['width'] - $logo_w - 5;
                 $y = 5;
                 break;
             case 4:
                 $x = 5;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 5:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 6:
                 $x = $this->imginfo['width'] - $logo_w;
                 $y = ($this->imginfo['height'] - $logo_h) / 2;
                 break;
             case 7:
                 $x = 5;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
             case 8:
                 $x = ($this->imginfo['width'] - $logo_w) / 2;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
             case 9:
                 $x = $this->imginfo['width'] - $logo_w - 5;
                 $y = $this->imginfo['height'] - $logo_h - 5;
                 break;
         }
         if ($this->imginfo['mime'] != 'image/png') {
             $color_photo = imagecreatetruecolor($this->imginfo['width'], $this->imginfo['height']);
         }
         $dst_photo = $this->loadsource();
         if ($dst_photo < 0) {
             return $dst_photo;
         }
         imagealphablending($dst_photo, true);
         imagesavealpha($dst_photo, true);
         if ($this->imginfo['mime'] != 'image/png') {
             imageCopy($color_photo, $dst_photo, 0, 0, 0, 0, $this->imginfo['width'], $this->imginfo['height']);
             $dst_photo = $color_photo;
         }
         if ($this->param['watermarktype'][$type] == 'png') {
             imageCopy($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h);
         } elseif ($this->param['watermarktype'][$type] == 'text') {
             if (($this->param['watermarktext']['shadowx'][$type] || $this->param['watermarktext']['shadowy'][$type]) && $this->param['watermarktext']['shadowcolor'][$type]) {
                 $shadowcolorrgb = explode(',', $this->param['watermarktext']['shadowcolor'][$type]);
                 $shadowcolor = imagecolorallocate($dst_photo, $shadowcolorrgb[0], $shadowcolorrgb[1], $shadowcolorrgb[2]);
                 imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax + $this->param['watermarktext']['shadowx'][$type], $y + $ay + $this->param['watermarktext']['shadowy'][$type], $shadowcolor, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
             }
             $colorrgb = explode(',', $this->param['watermarktext']['color'][$type]);
             $color = imagecolorallocate($dst_photo, $colorrgb[0], $colorrgb[1], $colorrgb[2]);
             imagettftext($dst_photo, $this->param['watermarktext']['size'][$type], $this->param['watermarktext']['angle'][$type], $x + $ax, $y + $ay, $color, $this->param['watermarktext']['fontpath'][$type], $watermarktextcvt);
         } else {
             imageAlphaBlending($watermark_logo, true);
             imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $this->param['watermarktrans'][$type]);
         }
         clearstatcache();
         if ($this->imginfo['mime'] == 'image/jpeg') {
             @$imagefunc($dst_photo, $this->target, $this->param['watermarkquality'][$type]);
         } else {
             @$imagefunc($dst_photo, $this->target);
         }
     }
     return 1;
 }
Example #29
0
 function watermark($target, $watermark_file, $ext, $watermarkstatus = 9, $watermarktrans = 50)
 {
     $gdsurporttype = array();
     if (function_exists('imageAlphaBlending') && function_exists('getimagesize')) {
         if (function_exists('imageGIF')) {
             $gdsurporttype[] = 'gif';
         }
         if (function_exists('imagePNG')) {
             $gdsurporttype[] = 'png';
         }
         if (function_exists('imageJPEG')) {
             $gdsurporttype[] = 'jpg';
             $gdsurporttype[] = 'jpeg';
         }
     }
     if ($gdsurporttype && in_array($ext, $gdsurporttype)) {
         $attachinfo = getimagesize($target);
         $watermark_logo = imageCreateFromGIF($watermark_file);
         $logo_w = imageSX($watermark_logo);
         $logo_h = imageSY($watermark_logo);
         $img_w = $attachinfo[0];
         $img_h = $attachinfo[1];
         $wmwidth = $img_w - $logo_w;
         $wmheight = $img_h - $logo_h;
         $animatedgif = 0;
         if ($attachinfo['mime'] == 'image/gif') {
             $fp = fopen($target, 'rb');
             $targetcontent = fread($fp, 9999999);
             fclose($fp);
             $animatedgif = strpos($targetcontent, 'NETSCAPE2.0') === FALSE ? 0 : 1;
         }
         if ($watermark_logo && $wmwidth > 10 && $wmheight > 10 && !$animatedgif) {
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     $dst_photo = imageCreateFromJPEG($target);
                     break;
                 case 'image/gif':
                     $dst_photo = imageCreateFromGIF($target);
                     break;
                 case 'image/png':
                     $dst_photo = imageCreateFromPNG($target);
                     break;
             }
             switch ($watermarkstatus) {
                 case 1:
                     $x = +5;
                     $y = +5;
                     break;
                 case 2:
                     $x = ($logo_w + $img_w) / 2;
                     $y = +5;
                     break;
                 case 3:
                     $x = $img_w - $logo_w - 5;
                     $y = +5;
                     break;
                 case 4:
                     $x = +5;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 5:
                     $x = ($logo_w + $img_w) / 2;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 6:
                     $x = $img_w - $logo_w;
                     $y = ($logo_h + $img_h) / 2;
                     break;
                 case 7:
                     $x = +5;
                     $y = $img_h - $logo_h - 5;
                     break;
                 case 8:
                     $x = ($logo_w + $img_w) / 2;
                     $y = $img_h - $logo_h;
                     break;
                 case 9:
                     $x = $img_w - $logo_w - 5;
                     $y = $img_h - $logo_h - 5;
                     break;
             }
             imageAlphaBlending($watermark_logo, FALSE);
             imagesavealpha($watermark_logo, TRUE);
             imageCopyMerge($dst_photo, $watermark_logo, $x, $y, 0, 0, $logo_w, $logo_h, $watermarktrans);
             switch ($attachinfo['mime']) {
                 case 'image/jpeg':
                     imageJPEG($dst_photo, $target);
                     break;
                 case 'image/gif':
                     imageGIF($dst_photo, $target);
                     break;
                 case 'image/png':
                     imagePNG($dst_photo, $target);
                     break;
             }
         }
     }
 }
Example #30
0
/**
 * Faster method than only calling imagecopyresampled()
 *
 * @return boolean Success/fail
 */
function fastImageCopyResampled(&$dst_image, &$src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $system, $quality = 3)
{
    /*
    Optional "quality" parameter (defaults is 3). Fractional values are allowed, for example 1.5.
    1 = Up to 600 times faster. Poor results, just uses imagecopyresized but removes black edges.
    2 = Up to 95 times faster. Images may appear too sharp, some people may prefer it.
    3 = Up to 60 times faster. Will give high quality smooth results very close to imagecopyresampled.
    4 = Up to 25 times faster. Almost identical to imagecopyresampled for most images.
    5 = No speedup. Just uses imagecopyresampled, highest quality but no advantage over imagecopyresampled.
    */
    if (empty($src_image) || empty($dst_image) || $quality <= 0) {
        return false;
    }
    if (preg_match("/png/", $system[0]) || preg_match("/gif/", $system[0])) {
        $colorcount = imagecolorstotal($src_image);
        if ($colorcount <= 256 && $colorcount != 0) {
            imagetruecolortopalette($dst_image, true, $colorcount);
            imagepalettecopy($dst_image, $src_image);
            $transparentcolor = imagecolortransparent($src_image);
            imagefill($dst_image, 0, 0, $transparentcolor);
            imagecolortransparent($dst_image, $transparentcolor);
        } else {
            imageAlphaBlending($dst_image, false);
            imageSaveAlpha($dst_image, true);
            //If the image has Alpha blending, lets save it
        }
    }
    if ($quality < 5 && ($dst_w * $quality < $src_w || $dst_h * $quality < $src_h)) {
        $temp = imagecreatetruecolor($dst_w * $quality + 1, $dst_h * $quality + 1);
        if (preg_match("/png/", $system[0])) {
            $background = imagecolorallocate($temp, 0, 0, 0);
            ImageColorTransparent($temp, $background);
            // make the new temp image all transparent
            imagealphablending($temp, false);
            // turn off the alpha blending to keep the alpha channel
        }
        imagecopyresized($temp, $src_image, 0, 0, $src_x, $src_y, $dst_w * $quality + 1, $dst_h * $quality + 1, $src_w, $src_h);
        imagecopyresampled($dst_image, $temp, $dst_x, $dst_y, 0, 0, $dst_w, $dst_h, $dst_w * $quality, $dst_h * $quality);
        imagedestroy($temp);
    } else {
        imagecopyresampled($dst_image, $src_image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
    }
    return true;
}