/**
  * Read image
  *
  * @param   string uri
  * @return  resource
  * @throws  img.ImagingException
  */
 public function readImageFromUri($uri)
 {
     if (false === ($r = imagecreatefromgd2($uri))) {
         $e = new \img\ImagingException('Cannot read image from "' . $uri . '"');
         \xp::gc(__FILE__);
         throw $e;
     }
     return $r;
 }
 /**
  * Read image via imagecreatefromgd2()
  *
  * @param   string uri
  * @return  resource
  * @throws  img.ImagingException
  */
 protected function readImage0($uri)
 {
     if (FALSE === ($r = imagecreatefromgd2($uri))) {
         $e = new ImagingException('Cannot read image');
         xp::gc(__FILE__);
         throw $e;
     }
     return $r;
 }
Beispiel #3
0
function createThumb($filename, $fondo, $w, $h)
{
    error_reporting(E_ERROR);
    if (imagecreatefromjpeg($filename) || imagecreatefrompng($filename) || imagecreatefromgif($filename) || imagecreatefromgd2($filename)) {
        return $this->jpegThumb($filename, $fondo, $w, $h);
    } else {
        debug("IMAGE NOT SUPPORTED " . mime_content_type($filename), "white");
        return false;
    }
}
Beispiel #4
0
 function testSaveToFile()
 {
     $handle = imagecreatefromgif(IMG_PATH . '100x100-color-hole.gif');
     $this->mapper->save($handle, IMG_PATH . 'temp/test.gd2');
     $this->assertTrue(filesize(IMG_PATH . 'temp/test.gd2') > 0);
     imagedestroy($handle);
     // file is a valid image
     $handle = imagecreatefromgd2(IMG_PATH . 'temp/test.gd2');
     $this->assertTrue(WideImage::isValidImageHandle($handle));
     imagedestroy($handle);
 }
Beispiel #5
0
 /**
  * 根据原始文件的扩展名,返回从原始文件创建的一个画布
  * @return resource 返回从原始文件取得的一个图像
  */
 private function _from()
 {
     switch ($this->src_img_ext) {
         case "gd2":
             return imagecreatefromgd2($this->src_img);
         case "gd":
             return imagecreatefromgd($this->src_img);
         case "gif":
             return imagecreatefromgif($this->src_img);
         case "jpeg":
             return imagecreatefromjpeg($this->src_img);
         case "jpg":
             return imagecreatefromjpeg($this->src_img);
         case "png":
             return imagecreatefrompng($this->src_img);
         default:
             return FALSE;
     }
 }
function open_image($file)
{
    $im = @imagecreatefromjpeg($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromgif($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefrompng($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromgd($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromgd2($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromwbmp($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromxbm($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromxpm($file);
    if ($im !== false) {
        return $im;
    }
    $im = @imagecreatefromstring(file_get_contents($file));
    if ($im !== false) {
        return $im;
    }
    return false;
}
Beispiel #7
0
 public static function registerBuiltInParsers()
 {
     static $registered = false;
     if ($registered) {
         return;
     }
     $registered = true;
     $parsers = ["image/gif" => function ($_filename) {
         return @imagecreatefromgif($_filename);
     }, "image/png" => function ($_filename) {
         return @imagecreatefrompng($_filename);
     }, "image/bmp" => function ($_filename) {
         return @ExtLib::imageCreateFromBmp($_filename);
     }, "image/jpeg" => function ($_filename) {
         return @imagecreatefromjpeg($_filename);
     }, "application/octet-stream" => function ($_filename) {
         return @imagecreatefromgd2($_filename);
     }];
     foreach ($parsers as $type => $parser) {
         static::registerParser($type, $parser);
     }
 }
Beispiel #8
0
 /**
  * load gd resource from dest file
  * @param resource $fsrc the gd2 file source
  * @return boolean true on success false otherwise
  */
 public static function loadGD($fsrc, $fileName)
 {
     if (@file_exists($fsrc)) {
         $fsrc = $fsrc . $fileName . ".gd2";
         $result = @imagecreatefromgd2($fsrc);
         if (!$result) {
             self::logger("loadGD", "Unable To Load GD Resource Into ({$dest})");
         }
         return $result;
     }
     self::logger("loadGD", "({$fsrc}) Is Not Exist");
     return false;
 }
Beispiel #9
0
 public function loadGD2($sFile)
 {
     $this->rImage = imagecreatefromgd2($sFile);
 }
Beispiel #10
0
 public static function open($file, $type)
 {
     // @rule: Test for JPG image extensions
     if (function_exists('imagecreatefromjpeg') && ($type == 'image/jpg' || $type == 'image/jpeg' || $type == 'image/pjpeg')) {
         $im = @imagecreatefromjpeg($file);
         if ($im !== false) {
             return $im;
         }
     }
     // @rule: Test for png image extensions
     if (function_exists('imagecreatefrompng') && ($type == 'image/png' || $type == 'image/x-png')) {
         $im = @imagecreatefrompng($file);
         if ($im !== false) {
             return $im;
         }
     }
     // @rule: Test for png image extensions
     if (function_exists('imagecreatefromgif') && $type == 'image/gif') {
         $im = @imagecreatefromgif($file);
         if ($im !== false) {
             return $im;
         }
     }
     if (function_exists('imagecreatefromgd')) {
         # GD File:
         $im = @imagecreatefromgd($file);
         if ($im !== false) {
             return true;
         }
     }
     if (function_exists('imagecreatefromgd2')) {
         # GD2 File:
         $im = @imagecreatefromgd2($file);
         if ($im !== false) {
             return true;
         }
     }
     if (function_exists('imagecreatefromwbmp')) {
         # WBMP:
         $im = @imagecreatefromwbmp($file);
         if ($im !== false) {
             return true;
         }
     }
     if (function_exists('imagecreatefromxbm')) {
         # XBM:
         $im = @imagecreatefromxbm($file);
         if ($im !== false) {
             return true;
         }
     }
     if (function_exists('imagecreatefromxpm')) {
         # XPM:
         $im = @imagecreatefromxpm($file);
         if ($im !== false) {
             return true;
         }
     }
     // If all failed, this photo is invalid
     return false;
 }
 //print "suffix: '$suffix'<br />";
 mysqltest();
 if ($suffix == "jpeg" || $suffix == "jpg" || $suffix == "jif" || $suffix == "jpe") {
     $im = @imagecreatefromjpeg($localtempfile);
 } else {
     if ($suffix == "png") {
         $im = @imagecreatefrompng($localtempfile);
     } else {
         if ($suffix == "gif") {
             $im = @imagecreatefromgif($localtempfile);
         } else {
             if ($suffix == "gd") {
                 $im = @imagecreatefromgd($localtempfile);
             } else {
                 if ($suffix == "gd2") {
                     $im = @imagecreatefromgd2($localtempfile);
                 } else {
                     if ($suffix == "wbmp") {
                         $im = @imagecreatefromwbmp($localtempfile);
                     }
                 }
             }
         }
     }
 }
 mysqltest();
 if (!$im) {
     $output = "." . $thumb_folder . "/dummy.png";
     // create name for thumbnail
     $im = @ImageCreate(150, 50) or die('');
     $background_color = ImageColorAllocate($im, 189, 228, 212);
Beispiel #12
0
 function _crear($path, $medida = 127, $formato = 'jpg', $nombre, $vert = false)
 {
     $nom = basename($path, '.' . $formato);
     $gene = $nombre . '_generatriz.gd2';
     $dir = dirname($path) . '/' . $gene;
     if (file_exists($dir)) {
         //si existe la generatriz
         $image = imagecreatefromgd2($dir);
         $oancho = imagesx($image);
         $oalto = imagesy($image);
         if ($vert) {
             $ancho = $medida;
             $alto = round($ancho * $oalto / $oancho);
         } else {
             $alto = $medida;
             $ancho = round($alto * $oancho / $oalto);
         }
         $im = imagecreatetruecolor($ancho, $alto);
         imagecopyresampled($im, $image, 0, 0, 0, 0, $ancho, $alto, $oancho, $oalto);
     } else {
         //si no existe la generatriz
         $rif = $this->datasis->traevalor('RIF');
         $titu = empty($rif) ? 'Logotipo' : $rif;
         if ($vert) {
             $ancho = $medida;
             $alto = 80;
         } else {
             $alto = $medida;
             $ancho = 127;
         }
         $im = imagecreate($ancho, $alto);
         $white = imagecolorallocate($im, 255, 255, 255);
         $black = imagecolorallocate($im, 0, 0, 0);
         $font_ancho = imagefontwidth(5);
         // para calcular el grosor de la fuente
         $string_alto = imagefontheight(5);
         $string_ancho = $font_ancho * strlen($titu);
         //imagefill($im, 0, 0, $white);      //Se crea una imagen con un unico color
         $x = floor(($ancho - $string_ancho) / 2);
         $y = floor(($alto - $string_alto) / 2);
         imagestring($im, 5, $x, $y, $titu, $black);
         //El 5 viene a ser el tamaño de la letra 1-5
         imageline($im, $x, $y, $x + $string_ancho, $y, $black);
         imageline($im, $x, $y + $string_alto, $x + $string_ancho, $y + $string_alto, $black);
     }
     if (!$this->write) {
         $path = null;
     }
     switch ($formato) {
         case 'jpg':
             imagejpeg($im, $path);
             break;
         case 'gif':
             imagegif($im, $path);
             break;
         case 'png':
             imagepng($im, $path);
             break;
     }
     imagedestroy($im);
 }
Beispiel #13
0
 private function load($path, $type)
 {
     $image = null;
     // jpeg
     if (function_exists('imagecreatefromjpeg') && ($type == 'image/jpg' || $type == 'image/jpeg' || $type == 'image/pjpeg')) {
         $image = @imagecreatefromjpeg($path);
         if ($image !== false) {
             return $image;
         }
     }
     // png
     if (function_exists('imagecreatefrompng') && ($type == 'image/png' || $type == 'image/x-png')) {
         $image = @imagecreatefrompng($path);
         if ($image !== false) {
             return $image;
         }
     }
     // gif
     if (function_exists('imagecreatefromgif') && $type == 'image/gif') {
         $image = @imagecreatefromgif($path);
         if ($image !== false) {
             return $image;
         }
     }
     // gd
     if (function_exists('imagecreatefromgd')) {
         $image = imagecreatefromgd($path);
         if ($image !== false) {
             return $image;
         }
     }
     // gd2
     if (function_exists('imagecreatefromgd2')) {
         $image = @imagecreatefromgd2($path);
         if ($image !== false) {
             return $image;
         }
     }
     // bmp
     if (function_exists('imagecreatefromwbmp')) {
         $image = @imagecreatefromwbmp($path);
         if ($image !== false) {
             return $image;
         }
     }
     return $image;
 }
Beispiel #14
0
<?php

$cwd = dirname(__FILE__);
echo "JPEG to GD1 conversion: ";
echo imagegd(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd1") ? 'ok' : 'failed';
echo "\n";
echo "JPEG to GD2 conversion: ";
echo imagegd2(imagecreatefromjpeg($cwd . "/conv_test.jpeg"), $cwd . "/test.gd2") ? 'ok' : 'failed';
echo "\n";
echo "GD1 to JPEG conversion: ";
echo imagejpeg(imagecreatefromgd($cwd . "/test.gd1"), $cwd . "/test_gd1.jpeg") ? 'ok' : 'failed';
echo "\n";
echo "GD2 to JPEG conversion: ";
echo imagejpeg(imagecreatefromgd2($cwd . "/test.gd2"), $cwd . "/test_gd2.jpeg") ? 'ok' : 'failed';
echo "\n";
@unlink($cwd . "/test.gd1");
@unlink($cwd . "/test.gd2");
@unlink($cwd . "/test_gd1.jpeg");
@unlink($cwd . "/test_gd2.jpeg");
Beispiel #15
0
 /**
  * Make the $this->hdlWork to be an exact copy
  * of $this->hdlOrig resource
  *
  * @return object $this
  */
 protected function copyOrig()
 {
     d('start cloning orig resource');
     $tmpfname = \tempnam($this->Ini->TEMP_DIR, "imgclone");
     d('$tmpfname: ' . $tmpfname);
     \imagegd2($this->hdlOrig, $tmpfname);
     $this->hdlWork = \imagecreatefromgd2($tmpfname);
     @\unlink($tmpfname);
     return $this;
 }
Beispiel #16
0
 public function createFrom(string $type, string $source, array $settings = NULL)
 {
     $type = strtolower($type);
     switch ($type) {
         case 'gd2':
             $return = imagecreatefromgd2($source);
             break;
         case 'gd':
             $return = imagecreatefromgd($source);
             break;
         case 'gif':
             $return = imagecreatefromgif($source);
             break;
         case 'jpeg':
             $return = imagecreatefromjpeg($source);
             break;
         case 'png':
             $return = imagecreatefrompng($source);
             break;
         case 'string':
             $return = imagecreatefromstring($source);
             break;
         case 'wbmp':
             $return = imagecreatefromwbmp($source);
             break;
         case 'webp':
             $return = imagecreatefromwebp($source);
             break;
         case 'xbm':
             $return = imagecreatefromxbm($source);
             break;
         case 'xpm':
             $return = imagecreatefromxpm($source);
             break;
         case 'gd2p':
             $return = imagecreatefromgd2part($source, isset($settings['x']) ? $settings['x'] : NULL, isset($settings['y']) ? $settings['y'] : NULL, isset($settings['width']) ? $settings['width'] : NULL, isset($settings['height']) ? $settings['height'] : NULL);
     }
     return $return;
 }
Beispiel #17
0
 private static function get_image($name, $opacity = 1, $brightness = 0, $contrast = 0, $r = 0, $g = 0, $b = 0)
 {
     static $locmem_cache = array();
     # Check locmem cache.
     $key = "{$name}/{$opacity}/{$brightness}/{$contrast}/{$r}/{$g}/{$b}";
     if (!isset($locmem_cache[$key])) {
         # Miss. Check default cache.  WRTODO: upgrade to normal Cache?
         try {
             $cache_key = "tilesrc/" . Okapi::$revision . "/" . self::$VERSION . "/" . $key;
             $gd2_path = self::$USE_STATIC_IMAGE_CACHE ? FileCache::get_file_path($cache_key) : null;
             if ($gd2_path === null) {
                 throw new Exception("Not in cache");
             }
             # File cache hit. GD2 files are much faster to read than PNGs.
             # This can throw an Exception (see bug#160).
             $locmem_cache[$key] = imagecreatefromgd2($gd2_path);
         } catch (Exception $e) {
             # Miss again (or error decoding). Read the image from PNG.
             $locmem_cache[$key] = imagecreatefrompng($GLOBALS['rootpath'] . "okapi/static/tilemap/{$name}.png");
             # Apply all wanted effects.
             if ($opacity != 1) {
                 self::change_opacity($locmem_cache[$key], $opacity);
             }
             if ($contrast != 0) {
                 imagefilter($locmem_cache[$key], IMG_FILTER_CONTRAST, $contrast);
             }
             if ($brightness != 0) {
                 imagefilter($locmem_cache[$key], IMG_FILTER_BRIGHTNESS, $brightness);
             }
             if ($r != 0 || $g != 0 || $b != 0) {
                 imagefilter($locmem_cache[$key], IMG_FILTER_GRAYSCALE);
                 imagefilter($locmem_cache[$key], IMG_FILTER_COLORIZE, $r, $g, $b);
             }
             # Cache the result.
             ob_start();
             imagegd2($locmem_cache[$key]);
             $gd2 = ob_get_clean();
             FileCache::set($cache_key, $gd2);
         }
     }
     return $locmem_cache[$key];
 }
Beispiel #18
0
 /**
  * Neues Bild Stueckweise erstellen
  */
 private function copyResampledPart(&$image, &$newImage, $newImageInfo, $newWidth, $newHeight, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $bgColor = null)
 {
     // Breite und Hoehe angegeben?
     if ($newWidth <= 0 && $newHeight <= 0) {
         // Fehler
         return;
     }
     // temporaeres Verzeichnis vorhanden
     if (!empty($this->tempDir) && file_exists($this->tempDir)) {
         // Ja -> verwenden
         $tmpDir = $this->tempDir;
     } else {
         // Nein -> temporaeres Verzeichnis des Systems verwenden
         $tmpDir = sys_get_temp_dir();
     }
     // Maximial Breite der einzelnen Bereich ermitteln
     $partWidth = 50;
     $maxUsedMemory = $this->getMemoryLimit() - memory_get_usage();
     if ($maxUsedMemory > 0) {
         do {
             $partWidth = $newImageInfo['width'] = (int) ceil($newImageInfo['width'] / 2);
             $requiredMemory = $this->getRequiredMemory($newImageInfo);
         } while ($partWidth > 50 && $maxUsedMemory < $requiredMemory);
     }
     if ($partWidth < 50) {
         $partWidth = 50;
     }
     // Bild in einzelne Bereich zerlegen
     $partImages = array();
     $partX = 0;
     while ($partX < $newWidth) {
         $partImage = null;
         $success = $this->doCopyResampled($image, $partImage, $this->imageType, $partWidth, $newHeight, $dst_x - $partX, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h, $bgColor);
         if ($success && $partImage) {
             $temp_file = tempnam($tmpDir, 'part_img_');
             if (!imagegd2($partImage, $temp_file)) {
                 return false;
             }
             $partImages[] = array('x' => $partX, 'file' => $temp_file);
             imagedestroy($partImage);
             gc_collect_cycles();
         } else {
             return false;
         }
         $partX += $partWidth;
     }
     // Originalbild schliessen
     imagedestroy($image);
     gc_collect_cycles();
     $image = null;
     // neues Bild erstellen
     $newImage = imagecreatetruecolor($newWidth, $newHeight);
     if (!$newImage) {
         return false;
     }
     // Neues Bild aus den einzelne Bereich erstellen
     $first = true;
     foreach ($partImages as $nextPart) {
         $partImage = imagecreatefromgd2($nextPart['file']);
         unlink($nextPart['file']);
         if ($newImage && $partImage) {
             $this->doCopyResampled($partImage, $newImage, $this->imageType, $newWidth, $newHeight, $nextPart['x'], 0, 0, 0, $partWidth, $newHeight, $partWidth, $newHeight, $bgColor, $first);
         }
         if ($partImage) {
             imagedestroy($partImage);
         }
         $first = false;
     }
     // Status zurueckgeben
     return $newImage ? true : false;
 }
Beispiel #19
0
        if (function_exists("imagecreatefromxpm")) {
            $img = @imagecreatefromxpm($file);
        } else {
            show_plain($file);
        }
        break;
    case 'gd':
        if (function_exists("imagecreatefromgd")) {
            $img = @imagecreatefromgd($file);
        } else {
            show_plain($file);
        }
        break;
    case 'gd2':
        if (function_exists("imagecreatefromgd2")) {
            $img = @imagecreatefromgd2($file);
        } else {
            show_plain($file);
        }
        break;
    default:
        //we are not stupid...
        header("Content-type: text/html");
        echo "<html><head></head><body>Not an image</body></html>";
        exit;
        break;
}
$width = @imagesx($img);
$height = @imagesy($img);
$newwidth = $_REQUEST['width'];
if (empty($newidth)) {
Beispiel #20
0
 public function load($uri)
 {
     return @imagecreatefromgd2($uri);
 }
Beispiel #21
0
 /**
  * Open image file
  */
 function _openImage($file)
 {
     # JPEG:
     $im = @imagecreatefromjpeg($file);
     if ($im !== false) {
         return $im;
     }
     # GIF:
     $im = @imagecreatefromgif($file);
     if ($im !== false) {
         return $im;
     }
     # PNG:
     $im = @imagecreatefrompng($file);
     if ($im !== false) {
         return $im;
     }
     # GD File:
     $im = @imagecreatefromgd($file);
     if ($im !== false) {
         return $im;
     }
     # GD2 File:
     $im = @imagecreatefromgd2($file);
     if ($im !== false) {
         return $im;
     }
     # WBMP:
     $im = @imagecreatefromwbmp($file);
     if ($im !== false) {
         return $im;
     }
     # XBM:
     $im = @imagecreatefromxbm($file);
     if ($im !== false) {
         return $im;
     }
     # XPM:
     $im = @imagecreatefromxpm($file);
     if ($im !== false) {
         return $im;
     }
     # Try and load from string:
     $im = @imagecreatefromstring(file_get_contents($file));
     if ($im !== false) {
         return $im;
     }
 }
 function imagecreatefromfilegamma($fisier, $g1, $g2)
 {
     if (eregi(".gif", $fisier)) {
         $im = imagecreatefromgif($fisier);
     }
     if (eregi(".jpg", $fisier)) {
         $im = imagecreatefromjpeg($fisier);
     }
     if (eregi(".jpeg", $fisier)) {
         $im = imagecreatefromjpeg($fisier);
     }
     if (eregi(".png", $fisier)) {
         $im = imagecreatefrompng($fisier);
     }
     if (eregi(".gd", $fisier)) {
         $im = imagecreatefromgd($fisier);
     }
     if (eregi(".gd2", $fisier)) {
         $im = imagecreatefromgd2($fisier);
     }
     if (eregi(".xbm", $fisier)) {
         $im = imagecreatefromxbm($fisier);
     }
     imagefilter($im, IMG_FILTER_BRIGHTNESS, $g2);
     return $im;
 }
 public function imageUpload($sourceImageName = "", $destinationImageName = "", $allowedFormat = array(), $allowedImageSize = "", $thumbImageHeight = "", $thumbImageWidth = "", $thumbImageName = "", $uploadPath = "", $thumbUploadPath = "", $thumbCreateStatus = false)
 {
     global $conf;
     $imageErrorMessage = array();
     $sourceImage = str_replace("%20", "", $_FILES[$sourceImageName]["name"]);
     $uploadImagePath = $uploadPath . $destinationImageName;
     $sourceImageType = $_FILES[$sourceImageName]["type"];
     $sourceImageSize = $_FILES[$sourceImageName]["size"];
     if (empty($allowedFormat)) {
         $imageStatus = true;
     } else {
         if (in_array($sourceImageType, $allowedFormat)) {
             $imageStatus = true;
         } else {
             $imageStatus = false;
             return false;
         }
     }
     if ($allowedImageSize == "") {
         $imageStatus = true;
     } else {
         if ($sourceImageSize <= $allowedImageSize) {
             $imageStatus = true;
         } else {
             $imageStatus = false;
             return false;
         }
     }
     if ($imageStatus) {
         if (move_uploaded_file($_FILES[$sourceImageName]["tmp_name"], $uploadImagePath)) {
             $destinationImage = $uploadPath . $destinationImageName;
             if ($thumbCreateStatus && $thumbUploadPath != "") {
                 $thumbImage = $thumbUploadPath . $thumbImageName;
                 switch ($sourceImageType) {
                     case 'image/jpeg':
                         $img = imagecreatefromjpeg($destinationImage);
                         break;
                     case 'image/jpg':
                         $img = imagecreatefromjpeg($destinationImage);
                         break;
                     case 'image/gif':
                         $img = imagecreatefromgif($destinationImage);
                         break;
                     case 'image/png':
                         $img = imagecreatefrompng($destinationImage);
                         break;
                     case 'image/x-png':
                         $img = imagecreatefrompng($destinationImage);
                         break;
                     case 'image/bmp':
                         $img = imagecreatefromwbmp($destinationImage);
                         break;
                     default:
                         $img = imagecreatefromgd2($destinationImage);
                         break;
                 }
                 $sourceImageWidth = imagesx($img);
                 $sourceImageHeight = imagesy($img);
                 $tmp_img = imagecreatetruecolor($thumbImageWidth, $thumbImageHeight);
                 imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $thumbImageWidth, $thumbImageHeight, $sourceImageWidth, $sourceImageHeight);
                 switch ($sourceImageType) {
                     case 'image/jpeg':
                         imagejpeg($tmp_img, $thumbImage, 100);
                         break;
                     case 'image/jpg':
                         imagejpeg($tmp_img, $thumbImage, 100);
                         break;
                     case 'image/gif':
                         imagegif($tmp_img, $thumbImage, 100);
                         break;
                     case 'image/png':
                         imagepng($tmp_img, $thumbImage, 100);
                         break;
                     case 'image/x-png':
                         imagepng($tmp_img, $thumbImage, 100);
                         break;
                     case 'image/bmp':
                         imagewbmp($tmp_img, $thumbImage, 100);
                         break;
                 }
                 imagedestroy($tmp_img);
             }
             return true;
         } else {
             return false;
         }
     }
 }
Beispiel #24
0
 function load($uri)
 {
     return imagecreatefromgd2($uri);
 }
Beispiel #25
0
 function save()
 {
     $this->load->helper('gfx');
     if (!checkAuth(true, false, 'json')) {
         return;
     }
     if ($this->input->post('name') === false) {
         json_message('EDITOR_NAME_EMPTY');
         return;
     }
     $data = array('name' => $this->input->post('name'));
     if ($this->input->post('title')) {
         $data['title'] = $this->input->post('title');
     }
     if ($this->input->post('recommendation')) {
         $data['recommendation'] = $this->input->post('recommendation');
     }
     if ($this->input->post('ready')) {
         $data['ready'] = $this->input->post('ready');
     }
     if ($this->input->post('avatar')) {
         $a = $this->input->post('avatar');
         switch ($a) {
             case '(default)':
                 $data['avatar'] = '';
                 break;
             case '(gravatar)':
                 $data['avatar'] = '(gravatar)';
                 break;
             case '(myidtw)':
                 $data['avatar'] = '(myidtw)';
                 break;
             default:
                 if (preg_match('/^[0-9a-z\\/]+\\.(gif|jpg|jpeg|png)$/i', $a) && file_exists('./useravatars/' . $a)) {
                     $data['avatar'] = $a;
                 } else {
                     json_message('EDITOR_AVATAR_ERROR');
                     return;
                 }
         }
     }
     $this->load->config('gfx');
     if (!preg_match('/^[a-zA-Z0-9_\\-]+$/', $this->input->post('name')) || strlen($this->input->post('name')) < 3 || strlen($this->input->post('name')) > 200 || substr($this->input->post('name'), 0, 8) === '__temp__' || in_array($this->input->post('name'), $this->config->item('gfx_badname')) || $this->db->query('SELECT `id` FROM `users` ' . 'WHERE `name` = ' . $this->db->escape($this->input->post('name')) . ' AND `id` != ' . $this->session->userdata('id'))->num_rows() !== 0) {
         json_message('EDITOR_NAME_BAD');
         return;
     }
     $this->db->update('users', $data, array('id' => $this->session->userdata('id')));
     if ($this->db->affected_rows() === 1) {
         $infoChanged = true;
     } else {
         $infoChanged = false;
     }
     $this->session->set_userdata(array('name' => $this->input->post('name')));
     $data = array();
     if ($this->input->post('email') !== false) {
         $data['email'] = $this->input->post('email');
     }
     if ($this->input->post('web') !== false && (in_array(strtolower(substr($this->input->post('web'), 0, strpos($this->input->post('web'), ':'))), array('http', 'https', 'telnet', 'irc', 'ftp', 'nntp')) || $this->input->post('web') === '')) {
         $data['web'] = $this->input->post('web');
     }
     if ($this->input->post('blog') !== false && (in_array(strtolower(substr($this->input->post('blog'), 0, strpos($this->input->post('blog'), ':'))), array('http', 'https', 'telnet', 'irc', 'ftp', 'nntp')) || $this->input->post('blog') === '')) {
         $data['blog'] = $this->input->post('blog');
     }
     if ($this->input->post('bio') !== false) {
         $data['bio'] = $this->input->post('bio');
     }
     if ($this->input->post('forum') !== false && $this->input->post('forum') !== '(keep-the-forum-username)' && $this->input->post('forum') !== '') {
         $F = explode('::', $this->input->post('forum'), 3);
         if (count($F) === 3 && $F[0] === substr(md5($F[1] . $F[2] . substr($this->input->post('token'), 0, 16) . $this->config->item('gfx_forum_auth_token')), 16)) {
             $data['forum_id'] = $F[1];
             $data['forum_username'] = $F[2];
         } else {
             json_message('EDITOR_FORUM_CODE');
             return;
         }
     } elseif ($this->input->post('forum') === '') {
         $data['forum_id'] = '';
         $data['forum_username'] = '';
     }
     if ($this->input->post('features')) {
         $F = $this->input->post('features');
         $v = 0;
         for ($i = 0; $i < 3; $i++) {
             if (!isset($F[$i + 1]) || !is_numeric($F[$i + 1])) {
                 json_message('EDITOR_FEATURE_ERROR');
                 return;
             }
             $data['feature_' . $i] = $F[$i + 1];
             $v |= pow(2, $F[$i + 1]);
         }
         $data['features_victor'] = $v;
     }
     if ($data) {
         $this->db->update('users', $data, array('id' => $this->session->userdata('id')));
     }
     $query = $this->db->query('SELECT `id` FROM `u2g` WHERE `user_id` = ' . $this->session->userdata('id') . ' ORDER BY `order` ASC;');
     $row = $query->row_array(0);
     $this->db->update('u2g', array('group_id' => 1, 'order' => 1), array('id' => $row['id']));
     $i = 1;
     while ($i < $query->num_rows()) {
         if ($row = $query->row_array($i)) {
             $this->db->delete('u2g', array('id' => $row['id']));
         }
         $i++;
     }
     if ($this->input->post('addons')) {
         $query = $this->db->query('SELECT `id` FROM `u2a` WHERE `user_id` = ' . $this->session->userdata('id') . ' ORDER BY `order` ASC;');
         $i = 0;
         foreach ($this->input->post('addons') as $a) {
             // don't care about the keys
             if (!is_numeric($a['id'])) {
                 json_message('EDITOR_ADDON_ERROR');
                 return;
             }
             if ($i < $query->num_rows()) {
                 $row = $query->row_array($i);
                 $this->db->update('u2a', array('addon_id' => $a['id'], 'group_id' => $a['group'], 'order' => $i + 1), array('id' => $row['id']));
             } else {
                 $this->db->insert('u2a', array('addon_id' => $a['id'], 'group_id' => $a['group'], 'order' => $i + 1, 'user_id' => $this->session->userdata('id')));
             }
             $i++;
         }
         while ($i < $query->num_rows()) {
             if ($row = $query->row_array($i)) {
                 $this->db->delete('u2a', array('id' => $row['id']));
             }
             $i++;
         }
     }
     $this->load->library('cache');
     $this->cache->remove(strtolower($this->input->post('name')), 'user');
     $this->cache->remove($this->session->userdata('id'), 'header');
     //TBD: hide user id from user
     $d = './userstickers/' . dechex(intval($this->session->userdata('id')) >> 12) . '/' . dechex(intval($this->session->userdata('id') & pow(2, 12) - 1)) . '/';
     @mkdir($d, 0755, true);
     if (($infoChanged || $this->input->post('features') || !file_exists($d . 'featurecard.png') || !file_exists($d . 'featurecard-h.png')) && $this->db->query('SELECT ready FROM users WHERE id = ' . $this->session->userdata('id') . ';')->row()->ready === 'Y') {
         $F = array();
         for ($i = 0; $i < 3; $i++) {
             $feature = $this->db->query('SELECT features.name, features.title, features.description FROM features ' . 'INNER JOIN users ON features.id = users.feature_' . $i . ' WHERE users.id = ' . $this->session->userdata('id') . ';');
             $F[] = $feature->row_array();
             $feature->free_result();
         }
         unset($feature);
         if (!$this->input->post('title')) {
             $user = $this->db->query('SELECT title FROM `users` WHERE `id` = ' . $this->session->userdata('id') . ';');
             $title = $user->row()->title;
         } else {
             $title = $this->input->post('title');
         }
         // featurecard.html
         file_put_contents($d . 'featurecard.html', $this->load->view('userstickers/featurecard.php', array('name' => $this->input->post('name'), 'title' => $title, 'features' => $F), true));
         // featurecard.png
         $card = imagecreatefromgd2('./images/' . $this->config->item('language') . '/featurecard.gd2');
         /* $D = imagettfbbox(14, 0, $this->config->item('gfx_sticker_font'), $title);*/
         imagettftext($card, 14, 0, 30, 197, imagecolorallocate($card, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title);
         if (file_exists('./stickerimages/features/' . $F[0]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[0]['name'] . '.gd2'), 55, 75, 0, 0, 150, 20);
         }
         if (file_exists('./stickerimages/features/' . $F[1]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[1]['name'] . '.gd2'), 55, 97, 0, 0, 150, 20);
         }
         if (file_exists('./stickerimages/features/' . $F[2]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[2]['name'] . '.gd2'), 55, 119, 0, 0, 150, 20);
         }
         imagealphablending($card, true);
         imagesavealpha($card, true);
         imagepng($card, $d . 'featurecard.png');
         imagedestroy($card);
         // featurecard-h.png
         $card = imagecreatefromgd2('./images/' . $this->config->item('language') . '/featurecard-h.gd2');
         /* $D = imagettfbbox(14, 0, $this->config->item('gfx_sticker_font'), $title);*/
         imagettftext($card, 11.5, 0, 350, 28, imagecolorallocate($card, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title);
         if (file_exists('./stickerimages/features/' . $F[0]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[0]['name'] . '.gd2'), 186, 9, 0, 0, 150, 20);
         }
         if (file_exists('./stickerimages/features/' . $F[1]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[1]['name'] . '.gd2'), 186, 31, 0, 0, 150, 20);
         }
         if (file_exists('./stickerimages/features/' . $F[2]['name'] . '.gd2')) {
             imagecopy($card, imagecreatefromgd2('./stickerimages/features/' . $F[2]['name'] . '.gd2'), 272, 9, 0, 0, 150, 20);
         }
         imagealphablending($card, true);
         imagesavealpha($card, true);
         imagepng($card, $d . 'featurecard-h.png');
         imagedestroy($card);
         //smallsticker.png
         $sticker = imagecreatefromgd2('./images/' . $this->config->item('language') . '/smallsticker.gd2');
         /* $D = imagettfbbox(14, 0, $this->config->item('gfx_sticker_font'), $title);*/
         imagettftext($sticker, 13, 0, 67, 70, imagecolorallocate($sticker, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title);
         imagealphablending($sticker, true);
         imagesavealpha($sticker, true);
         imagepng($sticker, $d . 'smallsticker.png');
         imagedestroy($sticker);
         //smallsticker2.png
         $sticker = imagecreatefromgd2('./images/' . $this->config->item('language') . '/smallsticker2.gd2');
         /* $D = imagettfbbox(14, 0, $this->config->item('gfx_sticker_font'), $title);*/
         imagettftext($sticker, 11.5, 0, 57, 65, imagecolorallocate($sticker, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title);
         imagealphablending($sticker, true);
         imagesavealpha($sticker, true);
         imagepng($sticker, $d . 'smallsticker2.png');
         imagedestroy($sticker);
     }
     $this->load->view('json.php', array('jsonObj' => array('name' => $this->input->post('name'))));
 }
Beispiel #26
0
 /**
  * 创建图片
  *
  * @param $image
  * @param $image_type
  * @return resource
  */
 protected function createImage($image, $image_type)
 {
     switch ($image_type) {
         case 'jpg':
         case 'jpeg':
         case 'pjpeg':
             $res = imagecreatefromjpeg($image);
             break;
         case 'gif':
             $res = imagecreatefromgif($image);
             break;
         case 'png':
             $res = imagecreatefrompng($image);
             break;
         case 'bmp':
             $res = imagecreatefromwbmp($image);
             break;
         default:
             $res = imagecreatefromgd2($image);
             break;
     }
     return $res;
 }
Beispiel #27
0
 function _update_feature_images($title, $name)
 {
     $this->load->config('gfx');
     /* title gd2 cache */
     $text = imagecreatetruecolor(150, 20);
     imagesavealpha($text, true);
     imagefill($text, 0, 0, imagecolorallocatealpha($text, 255, 255, 255, 127));
     imagettftext($text, 12, 0, 0, 16, imagecolorallocate($text, 0, 0, 0), $this->config->item('gfx_sticker_font'), $title);
     imagegd2($text, './stickerimages/features/' . $name . '.gd2');
     //imagepng($text, './stickerimages/features/' . $name . '-text.png');
     /* singlefeature sticker */
     $bg = imagecreatefromgd2('./images/' . $this->config->item('language') . '/singlefeature.gd2');
     imagealphablending($bg, true);
     imagesavealpha($bg, true);
     $D = imagettfbbox(12, 0, $this->config->item('gfx_sticker_font'), $title);
     imagecopy($bg, $text, (150 - ($D[2] - $D[0])) / 2, 7, 0, 0, 150, 20);
     imagepng($bg, './stickerimages/features/' . $name . '.png');
     imagedestroy($text);
     imagedestroy($bg);
 }
Beispiel #28
0
<?php

$file = dirname(__FILE__) . '/src.gd2';
$im2 = imagecreatefromgd2($file);
echo 'test create from gd2: ';
echo imagecolorat($im2, 4, 4) == 0xffffff ? 'ok' : 'failed';
echo "\n";
$im3 = imagecreatefromgd2part($file, 4, 4, 2, 2);
echo 'test create from gd2 part: ';
echo imagecolorat($im2, 4, 4) == 0xffffff ? 'ok' : 'failed';
echo "\n";
Beispiel #29
0
 /**
  * 创建临时图象
  */
 private function create_im()
 {
     switch ($this->type) {
         case 'jpg':
         case 'jpeg':
         case 'pjpeg':
             $this->im = imagecreatefromjpeg($this->src_images);
             break;
         case 'gif':
             $this->im = imagecreatefromgif($this->src_images);
             break;
         case 'png':
             $this->im = imagecreatefrompng($this->src_images);
             break;
         case 'bmp':
             $this->im = imagecreatefromwbmp($this->src_images);
             break;
         default:
             $this->im = imagecreatefromgd2($this->src_images);
             break;
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function doLoadFromFile($filename)
 {
     $this->assertGdFile($filename);
     $result = @imagecreatefromgd2($filename);
     if (false == $result) {
         throw new CanvasCreationException(sprintf('Faild To Create The Gd Canvas From The File "%s"', $filename));
     }
     $this->setHandler($result);
 }