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;
     }
 }
Beispiel #2
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;
 }
Beispiel #3
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);
 }
Beispiel #4
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;
 }
Beispiel #5
0
function balloonpng($dir, $get_s, $get_color = null, $get_file = null)
{
    if ($get_s) {
        $smile = imagecreatefrompng($dir . "/images/smallballoontransp.png");
    } else {
        $smile = imagecreatefrompng($dir . "/images/bigballoontransp.png");
    }
    imageSaveAlpha($smile, true);
    if ($get_color != null) {
        $r = hexdec(substr($get_color, 0, 2));
        $g = hexdec(substr($get_color, 2, 2));
        $b = hexdec(substr($get_color, 4, 2));
        $kek = imagecolorallocate($smile, $r, $g, $b);
        if ($get_s) {
            imagefill($smile, 5, 5, $kek);
        } else {
            imagefill($smile, 12, 25, $kek);
        }
    }
    if ($get_file != null) {
        imagepng($smile, $get_file);
    } else {
        imagepng($smile);
    }
}
Beispiel #6
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;
         }
     }
 }
Beispiel #7
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;
 }
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;
}
Beispiel #9
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);
     }
 }
Beispiel #10
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;
 }
Beispiel #11
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;
 }
 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;
 }
Beispiel #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;
}
Beispiel #14
0
function build_monster($filename, $seed = '', $size = '')
{
    // init random seed
    if ($seed) {
        srand(hexdec(substr(md5($seed), 0, 6)));
    }
    // throw the dice for body parts
    $parts = array('legs' => rand(1, 5), 'hair' => rand(1, 5), 'arms' => rand(1, 5), 'body' => rand(1, 15), 'eyes' => rand(1, 15), 'mouth' => rand(1, 10));
    // create backgound
    $monster = @imagecreatetruecolor(120, 120) or die("GD image create failed");
    $white = imagecolorallocate($monster, 255, 255, 255);
    imagefill($monster, 0, 0, $white);
    // add parts
    foreach ($parts as $part => $num) {
        $file = dirname(__FILE__) . '/parts/' . $part . '_' . $num . '.png';
        $im = @imagecreatefrompng($file);
        if (!$im) {
            die('Failed to load ' . $file);
        }
        imageSaveAlpha($im, true);
        imagecopy($monster, $im, 0, 0, 0, 0, 120, 120);
        imagedestroy($im);
        // color the body
        if ($part == 'body') {
            $color = imagecolorallocate($monster, rand(20, 235), rand(20, 235), rand(20, 235));
            imagefill($monster, 60, 60, $color);
        }
    }
    // restore random seed
    if ($seed) {
        srand();
    }
    // resize if needed, then output
    if ($size && $size < 400) {
        $out = @imagecreatetruecolor($size, $size);
        if (!$out) {
            return false;
        }
        // Problems creating image!
        imagecopyresampled($out, $monster, 0, 0, 0, 0, $size, $size, 120, 120);
        imagepng($out, $filename);
        imagedestroy($out);
        imagedestroy($monster);
        return true;
    } else {
        //header ("Content-type: image/png");
        imagepng($monster, $filename);
        imagedestroy($monster);
        return true;
    }
}
Beispiel #15
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);
         }
     }
 }
Beispiel #16
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;
 }
/**
 * Generates a monster for the given seed
 * GDlib is required!
 */
function build_monster($seed = '', $size = '')
{
    // create 16 byte hash from seed
    $hash = md5($seed);
    // calculate part values from seed
    $parts = array('legs' => _get_monster_part(substr($hash, 0, 2), 1, 5), 'hair' => _get_monster_part(substr($hash, 2, 2), 1, 5), 'arms' => _get_monster_part(substr($hash, 4, 2), 1, 5), 'body' => _get_monster_part(substr($hash, 6, 2), 1, 15), 'eyes' => _get_monster_part(substr($hash, 8, 2), 1, 15), 'mouth' => _get_monster_part(substr($hash, 10, 2), 1, 10));
    // create background
    $monster = @imagecreatetruecolor(120, 120) or die("GD image create failed");
    $white = imagecolorallocate($monster, 255, 255, 255);
    imagefill($monster, 0, 0, $white);
    // add parts
    foreach ($parts as $part => $num) {
        $file = dirname(__FILE__) . '/parts/' . $part . '_' . $num . '.png';
        $im = @imagecreatefrompng($file);
        if (!$im) {
            die('Failed to load ' . $file);
        }
        imageSaveAlpha($im, true);
        imagecopy($monster, $im, 0, 0, 0, 0, 120, 120);
        imagedestroy($im);
        // color the body
        if ($part == 'body') {
            $r = _get_monster_part(substr($hash, 0, 4), 20, 235);
            $g = _get_monster_part(substr($hash, 4, 4), 20, 235);
            $b = _get_monster_part(substr($hash, 8, 4), 20, 235);
            $color = imagecolorallocate($monster, $r, $g, $b);
            imagefill($monster, 60, 60, $color);
        }
    }
    // restore random seed
    if ($seed) {
        srand();
    }
    // resize if needed, then output
    if ($size && $size < 400) {
        $out = @imagecreatetruecolor($size, $size) or die("GD image create failed");
        imagecopyresampled($out, $monster, 0, 0, 0, 0, $size, $size, 120, 120);
        header("Content-type: image/png");
        imagepng($out);
        imagedestroy($out);
        imagedestroy($monster);
    } else {
        header("Content-type: image/png");
        imagepng($monster);
        imagedestroy($monster);
    }
}
 public function indexAction()
 {
     $size = 300;
     $image = imagecreatetruecolor($size, $size);
     // something to get a white background with black border
     $back = imagecolorallocate($image, 255, 255, 255);
     $border = imagecolorallocate($image, 0, 0, 0);
     imagefilledrectangle($image, 0, 0, $size - 1, $size - 1, $back);
     imagerectangle($image, 0, 0, $size - 1, $size - 1, $border);
     $yellow_x = 100;
     $yellow_y = 75;
     $red_x = 120;
     $red_y = 165;
     $blue_x = 187;
     $blue_y = 125;
     $radius = 150;
     // allocate colors with alpha values
     $yellow = imagecolorallocatealpha($image, 255, 255, 0, 75);
     $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
     $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
     // drawing 3 overlapped circle
     imagefilledellipse($image, $yellow_x, $yellow_y, $radius, $radius, $yellow);
     imagefilledellipse($image, $red_x, $red_y, $radius, $radius, $red);
     imagefilledellipse($image, $blue_x, $blue_y, $radius, $radius, $blue);
     // don't forget to output a correct header!
     header('Content-type: image/png');
     // and finally, output the result
     imagepng($image);
     imagedestroy($image);
     exit;
     $im1 = imagecreatetruecolor(300, 100) or die("Error");
     imagealphablending($im1, true);
     imageSaveAlpha($im1, true);
     $color = '#FF0000';
     $textColorAllocated = ImageColorAllocate($im1, hexdec(substr($color, 1, 2)), hexdec(substr($color, 3, 2)), hexdec(substr($color, 5, 2)));
     $backgroundColor = '#FFFF00';
     //         $bgColor = ImageColorAllocate ($im1, hexdec(substr($backgroundColor,1,2)), hexdec(substr($backgroundColor,3,2)), hexdec(substr($backgroundColor,5,2)));
     $bgColor = imagecolorallocatealpha($im1, 255, 255, 255, 126);
     imageFill($im1, 0, 0, $bgColor);
     imageline($im1, 0, 0, 100, 100, $textColorAllocated);
     imagettftext($im1, 50, 0, 50, 50, $textColorAllocated, dirname(__FILE__) . '/Headline/arial.ttf', 'asdf');
     header('Content-Type: image/png');
     imagepng($im1);
     imagedestroy($im1);
     exit;
 }
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);
}
Beispiel #20
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;
 }
Beispiel #21
0
 function process()
 {
     global $CONFIG;
     $matches = array();
     if (!preg_match("/^([0-9a-zA-Z]+)\\.png\$/", $this->file, $matches)) {
         error_exit("Invalid image request for {$this->file}");
     }
     $code = $matches[1];
     $basepath = trim($CONFIG['paths']['base_url'], '/') . '/image/pins';
     $basefile = trim($CONFIG['paths']['file_path'], '/') . '/image/pins';
     $localfile = "{$basefile}/{$code}.png";
     if (file_exists($localfile)) {
         header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/{$code}.png");
     } else {
         if (!function_exists('ImageCreateFromPNG')) {
             header("Location: http://{$_SERVER['HTTP_HOST']}/{$basepath}/blank-marker.png");
         } else {
             $font = 'ttf-bitstream-vera/Vera';
             $size = 6;
             if (strlen($code) < 3) {
                 # Bigger image for number-only pins
                 $size = 8;
             }
             $im = ImageCreateFromPNG("{$basefile}/blank-marker.png");
             imageSaveAlpha($im, true);
             $tsize = ImageTTFBBox($size, 0, $font, $code);
             $textbg = ImageColorAllocate($im, 255, 119, 207);
             $black = ImageColorAllocate($im, 0, 0, 0);
             $dx = abs($tsize[2] - $tsize[0]);
             $dy = abs($tsize[5] - $tsize[3]);
             $x = (ImageSx($im) - $dx) / 2 + 1;
             $y = (ImageSy($im) - $dy) / 2;
             ImageTTFText($im, $size, 0, $x, $y, $black, $font, $code);
             header('Content-Type: image/png');
             ImagePNG($im);
             ImagePNG($im, $localfile);
             ImageDestroy($im);
         }
     }
     exit;
 }
Beispiel #22
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;
}
Beispiel #23
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;
 }
 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;
 }
Beispiel #25
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;
 }
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;
}
Beispiel #27
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);
         }
     }
 }
Beispiel #28
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');
 }
Beispiel #30
0
 /**
  * Add watermark to image
  *
  * @param string $imagePath
  * @param int $positionX
  * @param int $positionY
  * @param int $opacity
  * @param bool $tile
  * @return void
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity = 30, $tile = false)
 {
     list($watermarkSrcWidth, $watermarkSrcHeight, $watermarkFileType, ) = $this->_getImageOptions($imagePath);
     $this->_getFileAttributes();
     $watermark = call_user_func($this->_getCallback('create', $watermarkFileType, 'Unsupported watermark image format.'), $imagePath);
     $merged = false;
     if ($this->getWatermarkWidth() && $this->getWatermarkHeight() && $this->getWatermarkPosition() != self::POSITION_STRETCH) {
         $newWatermark = imagecreatetruecolor($this->getWatermarkWidth(), $this->getWatermarkHeight());
         imagealphablending($newWatermark, false);
         $col = imagecolorallocate($newWatermark, 255, 255, 255);
         imagecolortransparent($newWatermark, $col);
         imagefilledrectangle($newWatermark, 0, 0, $this->getWatermarkWidth(), $this->getWatermarkHeight(), $col);
         imagealphablending($newWatermark, true);
         imageSaveAlpha($newWatermark, true);
         imagecopyresampled($newWatermark, $watermark, 0, 0, 0, 0, $this->getWatermarkWidth(), $this->getWatermarkHeight(), imagesx($watermark), imagesy($watermark));
         $watermark = $newWatermark;
     }
     if ($this->getWatermarkPosition() == self::POSITION_TILE) {
         $tile = true;
     } elseif ($this->getWatermarkPosition() == self::POSITION_STRETCH) {
         $newWatermark = imagecreatetruecolor($this->_imageSrcWidth, $this->_imageSrcHeight);
         imagealphablending($newWatermark, false);
         $col = imagecolorallocate($newWatermark, 255, 255, 255);
         imagecolortransparent($newWatermark, $col);
         imagefilledrectangle($newWatermark, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight, $col);
         imagealphablending($newWatermark, true);
         imageSaveAlpha($newWatermark, true);
         imagecopyresampled($newWatermark, $watermark, 0, 0, 0, 0, $this->_imageSrcWidth, $this->_imageSrcHeight, imagesx($watermark), imagesy($watermark));
         $watermark = $newWatermark;
     } elseif ($this->getWatermarkPosition() == self::POSITION_CENTER) {
         $positionX = $this->_imageSrcWidth / 2 - imagesx($watermark) / 2;
         $positionY = $this->_imageSrcHeight / 2 - imagesy($watermark) / 2;
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     } elseif ($this->getWatermarkPosition() == self::POSITION_TOP_RIGHT) {
         $positionX = $this->_imageSrcWidth - imagesx($watermark);
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     } elseif ($this->getWatermarkPosition() == self::POSITION_TOP_LEFT) {
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     } elseif ($this->getWatermarkPosition() == self::POSITION_BOTTOM_RIGHT) {
         $positionX = $this->_imageSrcWidth - imagesx($watermark);
         $positionY = $this->_imageSrcHeight - imagesy($watermark);
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     } elseif ($this->getWatermarkPosition() == self::POSITION_BOTTOM_LEFT) {
         $positionY = $this->_imageSrcHeight - imagesy($watermark);
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     }
     if ($tile === false && $merged === false) {
         imagecopymerge($this->_imageHandler, $watermark, $positionX, $positionY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
     } else {
         $offsetX = $positionX;
         $offsetY = $positionY;
         while ($offsetY <= $this->_imageSrcHeight + imagesy($watermark)) {
             while ($offsetX <= $this->_imageSrcWidth + imagesx($watermark)) {
                 imagecopymerge($this->_imageHandler, $watermark, $offsetX, $offsetY, 0, 0, imagesx($watermark), imagesy($watermark), $this->getWatermarkImageOpacity());
                 $offsetX += imagesx($watermark);
             }
             $offsetX = $positionX;
             $offsetY += imagesy($watermark);
         }
     }
     imagedestroy($watermark);
     $this->refreshImageDimensions();
 }