コード例 #1
0
ファイル: XBM.php プロジェクト: moust/paint
 /**
  * Fix imagexbm bug where the output stream is still sent to stdout (https://bugs.php.net/bug.php?id=66339)
  *
  * @return void
  **/
 protected function imagexbm($output, $outputPath = null, $foreground = null)
 {
     if ($outputPath) {
         ob_start();
         imagexbm($output, $outputPath, $foreground);
         $data = ob_get_contents();
         ob_end_clean();
         file_put_contents($outputPath, $data, LOCK_EX);
     } else {
         imagexbm($output, $outputPath, $foreground);
     }
 }
コード例 #2
0
ファイル: GD.php プロジェクト: BGCX067/faculaframework2-git
 /**
  * Save image to disk
  *
  * @param string $file The path of the file will be save to
  *
  * @return bool Return true when saved, false for fail
  */
 public function save($file)
 {
     if ($this->imageRes) {
         if (!file_exists($file)) {
             switch ($this->imageInfo['Type']) {
                 case IMAGETYPE_GIF:
                     return imagegif($this->imageRes, $file);
                     break;
                 case IMAGETYPE_JPEG:
                     return imagejpeg($this->imageRes, $file, 85);
                     break;
                 case IMAGETYPE_PNG:
                     return imagepng($this->imageRes, $file);
                     break;
                 case IMAGETYPE_WBMP:
                     return imagewbmp($this->imageRes, $file);
                     break;
                 case IMAGETYPE_XBM:
                     return imagexbm($this->imageRes, $file);
                     break;
                 default:
                     $this->error = 'ERROR_IMAGE_HANDLER_IMAGE_INVALID';
                     return false;
                     break;
             }
         } else {
             $this->error = 'ERROR_IMAGE_HANDLER_SAVE_FILEEXISTED';
         }
     } else {
         $this->error = 'ERROR_IMAGE_HANDLER_IMAGE_NOTLOAD';
     }
     return false;
 }
コード例 #3
0
ファイル: GD2.php プロジェクト: trickyplan/codeine
            break;
        case 'JPX':
            // TODO JPX Support
            break;
        case 'JB2':
            // TODO JB2 Support
            break;
        case 'SWC':
            // TODO SWC Support
            break;
        case 'IFF':
            // TODO IFF Support
            break;
        case 'WBMP':
            if (isset($Call['ID'])) {
                imagewbmp($Call['Image']['Object'], $Call['ID']);
            } else {
                imagewbmp($Call['Image']['Object']);
            }
            break;
        case 'XBM':
            imagexbm($Call['Image']['Object'], $Call['ID']);
            break;
        case 'ICO':
            // TODO ICO Support
            break;
    }
    // TODO WEBP Support
    // TODO TGA Support
    return $Call;
});
コード例 #4
0
ファイル: Gd.php プロジェクト: smallmirror62/framework
 protected function _render($ext, $quality)
 {
     ob_start();
     if (strcasecmp($ext, "gif") == 0) {
         imagegif($this->_image);
         return ob_get_clean();
     }
     if (strcmp($ext, "jpg") == 0 || strcmp($ext, "jpeg") == 0) {
         imagejpeg($this->_image, null, $quality);
         return ob_get_clean();
     }
     if (strcmp($ext, "png") == 0) {
         imagejpeg($this->_image);
         return ob_get_clean();
     }
     if (strcmp($ext, "wbmp") == 0) {
         imagewbmp($this->_image);
         return ob_get_clean();
     }
     if (strcmp($ext, "xbm") == 0) {
         imagexbm($this->_image, null);
         return ob_get_clean();
     }
     throw new Exception("Installed GD does not support '" . $ext . "' images");
 }
コード例 #5
0
 /**
  * Output an image
  *
  * @param   resource handle
  * @return  bool
  */
 public function output($handle)
 {
     return imagexbm($handle, '', $this->foreground);
 }
コード例 #6
0
ファイル: PThumb.lib.php プロジェクト: rbrdevs/pydio-core
 /**
  * Prints out and cache the thumbnail. Returns verbose errors.
  * 
  * @access public
  * @param string $image The Relative Path to the image
  * @param integer $width The Width of the new thumbnail
  * @param integer $height The Height of the thumbnail
  * @param boolean $return_img Set to true to return the string instead of outputting it. Default to false
  * @param boolean $display_inline If set to true, heaers sent to browser will instruct it to display the image inline instead of asking the user to download. Defaults to true.
  * @return string
  * 
  */
 function print_thumbnail($image, $width, $height, $return_img = false, $display_inline = true, $target_file = false)
 {
     //Check parameters
     if (empty($image) || empty($width) || empty($height)) {
         return $this->set_error("Method print_thumbnail: Missing Parameters");
     }
     if (isset($this->currentRealFile) && is_file($this->currentRealFile)) {
         $image = $this->currentRealFile;
     }
     //Check whether $image is a remote address
     if ($this->is_remote($image) == 1) {
         $is_remote = true;
         //Check that file exists (Check only enabled in PHP 5 because only PHP 5 supports for checking remote files
         if (phpversion() >= 5) {
             if (!file_exists($image)) {
                 return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
             }
         }
         $image_data = $this->retrieve_remote_file($image, true, false, 1);
     } elseif ($this->is_remote($image) == 0) {
         $is_remote = false;
         if (!file_exists($image)) {
             return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
         }
         $image_data = implode("", file($image));
     }
     if (!is_string($image_data)) {
         return $this->set_error("Method print_thumbnail: Error, could not read image file '{$image}'.");
     }
     $array = $this->retrieve_image_data($image);
     if (!$array) {
         return $this->set_error("Method print_thumbnail: Unable to determine Image '{$image}' type and/or dimensions.");
     }
     list($ori_width, $ori_height, $format) = $array;
     //Check whether format is supported
     if (!array_key_exists($format, $this->file_ext)) {
         return $this->set_error("Method print_thumbnail: Image '{$image}' format is not supported.");
     }
     //Check that cache is enabled, cache DIR is writable, cache DIR exists
     if ($this->is_cacheable()) {
         //Passed eh? Generate the root dir of request file
         if ($is_remote != true) {
             $transformed = realpath($image);
             $hash = sha1_file($image);
         } else {
             $transformed = $image;
             $hash = sha1($image_data);
         }
         //Check if a version exists
         if ($this->exif_rotation) {
             $cache_file = $this->cache_dir . sha1($transformed) . "." . $width . "." . $height . ".rotated." . $hash . "." . $this->file_ext[$format];
         } else {
             $cache_file = $this->cache_dir . sha1($transformed) . "." . $width . "." . $height . "." . $hash . "." . $this->file_ext[$format];
         }
         if (file_exists($cache_file)) {
             if ($return_img == false) {
                 //AJXP_Logger::debug("Using Cache");
                 //die($cache_file);
                 header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
                 header("Cache-Control: no-store, no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 header("Content-Transfer-Encoding: binary");
                 header("Content-type: " . image_type_to_mime_type($format));
                 if ($display_inline == true) {
                     header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 } else {
                     header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 }
                 print implode("", file($cache_file));
                 die;
                 //Prepare redirectional URL
                 $redir_url = $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]) . "/" . $cache_file;
                 //Remove instances of double slashes "//"
                 $redir_url = str_replace("//", "/", $redir_url);
                 header("Location: http://{$redir_url}");
                 die;
             } else {
                 return implode("", file($cache_file));
             }
         } else {
             $handle = @opendir($this->cache_dir);
             if ($handle !== FALSE) {
                 while (false !== ($file = readdir($handle))) {
                     if ($this->exif_rotation) {
                         $rotated = "\\.rotated";
                     } else {
                         $rotated = "";
                     }
                     if (preg_match("/^" . preg_quote(sha1($transformed)) . "\\.[0-9]+\\.[0-9]+" . $rotated . "\\.([0-9a-z]{40})\\.(.+?)\$/i", $file, $matches)) {
                         //Hash is in [1]
                         //Check to see if the file data is the same. If it is, then don't delete it.
                         if ($matches[1] != $hash) {
                             $matched[] = $file;
                         }
                     }
                 }
                 closedir($handle);
                 if (!empty($matched)) {
                     for ($i = 0; $i <= count($matched) - 1; $i++) {
                         @unlink($this->cache_dir . $matched[$i]);
                     }
                 }
             }
         }
     }
     $gd_info = gd_info();
     //Special GIF handling
     if ($format == 1 && $gd_info["GIF Create Support"] != true) {
         //return $this -> set_error("Method print_thumbnail: Error, GIF support is unavaliable for PHP Version ".phpversion());
         //Image Outputted will be in PNG Format
         $format = 3;
     }
     $handle = @imagecreatefromstring($image_data);
     if ($handle == false) {
         return $this->set_error("Method print_thumbnail: Unsupported Image '{$image}' type");
     }
     //Exif Orientation patch
     $orientation = $this->exiforientation($image, true);
     if ($this->rotationsupported($orientation) and $orientation > 4) {
         $width2 = $width;
         $width = $height;
         $height = $width2;
     }
     //Now lets resize it
     //First lets create a new image handler which will be the thumbnailed image
     $thumbnail = imagecreatetruecolor($width, $height);
     if (!$thumbnail) {
         return $this->set_error("Method print_thumbnail: A thumbnail image '{$image}' could not be created");
     }
     /*  Image Format Special Handlinng */
     //GIF truecolour to palette - preserve transparency
     if ($format == 1) {
         imagetruecolortopalette($handle, true, 256);
     }
     //PNG Alpha Channel saving
     if ($format == 3) {
         //Set to save alpha channel info in source and destination
         imagealphablending($handle, false);
         imagesavealpha($handle, true);
         imagealphablending($thumbnail, false);
         imagesavealpha($thumbnail, true);
     }
     //Resize it
     if (!$this->fastimagecopyresampled($thumbnail, $handle, 0, 0, 0, 0, $width, $height, ImageSX($handle), ImageSY($handle), $this->thumb_quality)) {
         return $this->set_error("Method print_thumbnail: Failed resizing image '{$image}'.");
     }
     // Rotate if JPEG and Exif Information is available
     $orientation = $this->exiforientation($image, true);
     if ($this->rotationsupported($orientation)) {
         switch ($orientation) {
             case 2:
                 // mirror horizontal
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 break;
             case 3:
                 // rotate 180
                 $thumbnail = @imagerotate($thumbnail, 180, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 4:
                 // mirror vertical
                 @imageflip($thumbnail, IMG_FLIP_VERTICAL);
                 break;
             case 5:
                 // mirror horizontal, 90 rotate left
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 $thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 6:
                 // 90 rotate right
                 $thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 7:
                 // mirror horizontal, 90 rotate right
                 @imageflip($thumbnail, IMG_FLIP_HORIZONTAL);
                 $thumbnail = @imagerotate($thumbnail, -90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
             case 8:
                 // 90 rotate left
                 $thumbnail = @imagerotate($thumbnail, 90, imagecolorallocate($thumbnail, 255, 255, 255));
                 break;
         }
     }
     //Cache it
     if ($this->is_cacheable()) {
         switch ($format) {
             case 1:
                 $cached = @imagegif($thumbnail, $cache_file);
                 break;
             case 2:
                 $cached = @imageJPEG($thumbnail, $cache_file, 100);
                 break;
             case 3:
                 $cached = @imagepng($thumbnail, $cache_file);
                 break;
             case 15:
                 $cached = @imagewbmp($thumbnail, $cache_file);
                 break;
             case 16:
                 $cached = @imagexbm($thumbnail, $cache_file);
                 break;
             default:
                 $cached = false;
         }
         if (!$cached) {
             return $this->set_error("Method print_thumbnail 1: Error in cache generation of image '{$image}'.");
         }
     }
     if ($target_file != false) {
         $wrappers = stream_get_wrappers();
         $wrappers_re = '(' . implode('|', $wrappers) . ')';
         $isStream = preg_match("!^{$wrappers_re}://!", $target_file) === 1;
         if ($isStream) {
             $backToStreamTarget = $target_file;
             $target_file = tempnam(AJXP_Utils::getAjxpTmpDir(), "pthumb_");
         }
         switch ($format) {
             case 1:
                 $cached = @imagegif($thumbnail, $target_file);
                 break;
             case 2:
                 $cached = @imageJPEG($thumbnail, $target_file, 100);
                 break;
             case 3:
                 $cached = @imagepng($thumbnail, $target_file);
                 break;
             case 15:
                 $cached = @imagewbmp($thumbnail, $target_file);
                 break;
             case 16:
                 $cached = @imagexbm($thumbnail, $target_file);
                 break;
             default:
                 $cached = false;
         }
         if ($cached && $isStream) {
             $cached = @copy($target_file, $backToStreamTarget);
             @unlink($target_file);
         }
         if (!$cached) {
             return $this->set_error("Method print_thumbnail: Error in cache generation of image '{$image}'.");
         }
         return true;
     }
     if ($return_img == false) {
         header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
         header("Cache-Control: no-store, no-cache, must-revalidate");
         header("Pragma: no-cache");
         header("Content-Transfer-Encoding: binary");
         header("Content-type: " . image_type_to_mime_type($format));
         if ($display_inline == true) {
             header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         } else {
             header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         }
         if ($this->is_cacheable()) {
             echo implode("", file($cache_file));
         } else {
             switch ($format) {
                 case 1:
                     $outputed = @imagegif($thumbnail);
                     break;
                 case 2:
                     $outputed = @imageJPEG($thumbnail, null, 100);
                     break;
                 case 3:
                     $outputed = @imagepng($thumbnail);
                     break;
                 case 15:
                     $outpupted = @imagewbmp($thumbnail);
                     break;
                 case 16:
                     $outputed = @imagexbm($thumbnail, NULL);
                     break;
                 default:
                     $outputed = false;
             }
             if (!$outputed) {
                 return $this->set_error("Method print_thumbnail: Error outputting Image '{$image}'");
             }
         }
     } else {
         if ($this->is_cacheable()) {
             return implode("", file($cache_file));
         } else {
             return $this->set_error("Method print_thumbnail: Cannot return image '{$image}'! Cache must be enabled!");
         }
     }
     //Destroy the image
     imagedestroy($handle);
     imagedestroy($thumbnail);
     //Clear any cache; if needed
     $this->clear_cache();
 }
コード例 #7
0
ファイル: image.php プロジェクト: CDN-Sparks/owncloud
 /**
  * @brief Outputs/saves the image.
  */
 private function _output($filepath = null)
 {
     if ($filepath) {
         if (!file_exists(dirname($filepath))) {
             mkdir(dirname($filepath), 0777, true);
         }
         if (!is_writable(dirname($filepath))) {
             OC_Log::write('core', __METHOD__ . '(): Directory \'' . dirname($filepath) . '\' is not writable.', OC_Log::ERROR);
             return false;
         } elseif (is_writable(dirname($filepath)) && file_exists($filepath) && !is_writable($filepath)) {
             OC_Log::write('core', __METHOD__ . '(): File \'' . $filepath . '\' is not writable.', OC_Log::ERROR);
             return false;
         }
     }
     if (!$this->valid()) {
         return false;
     }
     $retval = false;
     switch ($this->imagetype) {
         case IMAGETYPE_GIF:
             $retval = imagegif($this->resource, $filepath);
             break;
         case IMAGETYPE_JPEG:
             $retval = imagejpeg($this->resource, $filepath);
             break;
         case IMAGETYPE_PNG:
             $retval = imagepng($this->resource, $filepath);
             break;
         case IMAGETYPE_XBM:
             $retval = imagexbm($this->resource, $filepath);
             break;
         case IMAGETYPE_WBMP:
             $retval = imagewbmp($this->resource, $filepath);
             break;
         case IMAGETYPE_BMP:
             $retval = imagebmp($this->resource, $filepath, $this->bit_depth);
             break;
         default:
             $retval = imagepng($this->resource, $filepath);
     }
     return $retval;
 }
コード例 #8
0
ファイル: index.php プロジェクト: philips/ewiki
                     imagesavealpha($new_image, TRUE);
                     switch ($page->getMimeType()) {
                         case 'image/gif':
                             imagegif($new_image);
                             break;
                         case 'image/jpeg':
                             imagejpeg($new_image);
                             break;
                         case 'image/png':
                             imagepng($new_image);
                             break;
                         case 'image/vnd.wap.wbmp':
                             imagewbmp($new_image);
                             break;
                         case 'image/x-xbitmap':
                             imagexbm($new_image);
                             break;
                         default:
                             throw new Exception(sprintf('unhandled image type: %s', $page->getMimeType()));
                     }
                     imagedestroy($new_image);
                 } else {
                     echo $page->object->data;
                 }
             } else {
                 // {{{2
                 throw new Exception(sprintf('unhandled action: %s', $action));
             }
         }
     }
 }
コード例 #9
0
ファイル: Image.class.php プロジェクト: gomezjsus/IAW
 /**
  * output
  * 
  * Output the image
  *
  * @param string $f (Optional) The filename to output to, if this is omitted the image is output to the browser
  * @return void
  * @access private
  * @author Dom Hastings
  */
 public function output($f = null, $options = array())
 {
     // merge in the options
     $options = array_merge_recursive_distinct(is_array($this->options['output']) ? $this->options['output'] : array(), is_array($options) ? $options : array());
     // if we're forcing an output type
     if (!empty($options['forceType'])) {
         $imageType = $options['forceType'];
     } else {
         $imageType = $this->info[2];
     }
     // use the correct output function
     switch ($imageType) {
         case IMAGETYPE_GIF:
             header('Content-type: ' . image_type_to_mime_type($imageType));
             imagegif($this->current, $f);
             break;
         case IMAGETYPE_JPEG:
         case IMAGETYPE_JPEG2000:
         case IMAGETYPE_JPC:
         case IMAGETYPE_JP2:
         case IMAGETYPE_JPX:
             header('Content-type: ' . image_type_to_mime_type($imageType));
             imagejpeg($this->current, $f, $options['jpeg']['quality']);
             break;
         case IMAGETYPE_PNG:
             header('Content-type: ' . image_type_to_mime_type($imageType));
             imagepng($this->current, $f, $options['png']['quality'], $options['png']['filters']);
             break;
         case IMAGETYPE_BMP:
         case IMAGETYPE_WBMP:
             header('Content-type: ' . image_type_to_mime_type($imageType));
             imagewbmp($this->current, $f);
             break;
         case IMAGETYPE_XBM:
             header('Content-type: ' . image_type_to_mime_type($imageType));
             imagexbm($this->current, $f);
             break;
         case IMAGETYPE_TIFF_II:
         case IMAGETYPE_TIFF_MM:
         case IMAGETYPE_IFF:
         case IMAGETYPE_JB2:
         case IMAGETYPE_SWF:
         case IMAGETYPE_PSD:
         case IMAGETYPE_SWC:
             // case IMAGETYPE_ICO:
         // case IMAGETYPE_ICO:
         default:
             break;
     }
 }
コード例 #10
0
ファイル: customresize.php プロジェクト: benjaco/fileeater
        imagejpeg($img, $imgname);
        break;
    case 'png':
        imagepng($img, $imgname);
        break;
    case 'bmp':
        imagebmp($img, $imgname);
        break;
    case 'gif':
        imagegif($img, $imgname);
        break;
    case 'vnd.wap.wbmp':
        imagewbmp($img, $imgname);
        break;
    case 'xbm':
        imagexbm($img, $imgname);
        break;
    default:
        imagejpeg($img, $imgname);
}
imagedestroy($img);
if ($fastemaal == "1") {
    /*$new_image = imagecreatetruecolor($ny_width, $ny_height);
        $aspect1 = $ny_height / $ny_width;
        $aspect1_o = $ny_width / $ny_height;
        $aspect2 = $after_croped_height / $after_croped_width;
    
        if ($aspect1 < $aspect2) {
            // lut i top og bund
            $start_y_f = round(($start_y/$full_height)*$height);
    
コード例 #11
0
ファイル: ClassImagens.php プロジェクト: mozelli/brcompras
 private function thumbnail($dir, $nome, $ext)
 {
     $new_width = 200;
     $new_height = $new_width;
     $diretorio = $dir . "/" . $nome;
     list($this->width, $this->height) = getimagesize($diretorio);
     switch ($this->type) {
         case 'image/jpeg':
             $img = imagecreatefromjpeg($diretorio);
             break;
         case 'image/jpg':
             $img = imagecreatefromjpeg($diretorio);
             break;
         case 'image/png':
             $img = imagecreatefrompng($diretorio);
             break;
         case 'image/bmp':
             $img = imagecreatefromwbmp($diretorio);
             break;
         case 'image/gif':
             $img = imagecreatefromgif($diretorio);
             break;
         default:
             # code...
             break;
     }
     //$img = imagecreatefrompng($diretorio);
     if ($this->width > $new_width) {
         $new_height = $new_width / $this->width * $this->height;
     }
     $thumb = imagecreatetruecolor($new_width, $new_height);
     imagecopyresampled($thumb, $img, 0, 0, 0, 0, $new_width, $new_height, $this->width, $this->height);
     switch ($this->type) {
         case 'image/jpeg':
             imagejpeg($thumb, "{$dir}/thumbnails/thumb_{$nome}");
             break;
         case 'image/jpg':
             imagejpeg($thumb, "{$dir}/thumbnails/thumb_{$nome}");
             break;
         case 'image/png':
             imagepng($thumb, "{$dir}/thumbnails/thumb_{$nome}");
             break;
         case 'image/bmp':
             imagexbm($thumb, "{$dir}/thumbnails/thumb_{$nome}");
             break;
         case 'image/gif':
             imagegif($thumb, "{$dir}/thumbnails/thumb_{$nome}");
             break;
         default:
             # code...
             break;
     }
 }
コード例 #12
0
 /**
  * -----------------------------
  * 给上传的图片添加水印
  * -----------------------------
  * @param  string $pic 要添加水印的图片
  * @param  string $waterPic 水印图片
  */
 private function imageWater($pic, $waterPic)
 {
     $picInfo = getimagesize($pic);
     $newPic = imagecreatetruecolor($picInfo[0], $picInfo[1]);
     //$white = imagecolorallocate($newPic,255,255,255);
     //imagefill($newPic,0,0,$white);
     switch ($picInfo[2]) {
         case 1:
             $spic = imagecreatefromgif($pic);
             break;
         case 2:
             $spic = imagecreatefromjpeg($pic);
             break;
         case 3:
             $spic = imagecreatefrompng($pic);
             break;
         case 15:
             $spic = imagecreatefromwbmp($pic);
             break;
         default:
             exit('不支持为此类型图片添加水印');
     }
     imagecopy($newPic, $spic, 0, 0, 0, 0, $picInfo[0], $picInfo[1]);
     imagedestroy($spic);
     $waterPicInfo = getimagesize($waterPic);
     switch ($waterPicInfo[2]) {
         case 1:
             $swaterPic = imagecreatefromgif($waterPic);
             break;
         case 2:
             $swaterPic = imagecreatefromjpeg($waterPic);
             break;
         case 3:
             $swaterPic = imagecreatefrompng($waterPic);
             break;
         case 15:
             $swaterPic = imagecreatefromwbmp($waterPic);
             break;
         default:
             exit('不支持此类型图片作为水印');
     }
     //将水印图片背景色设为透明色
     if ($this->waterPicBgcolor) {
         imagecolortransparent($swaterPic, $this->getColor($this->waterPicBgcolor, $swaterPic));
     }
     imagecopymerge($newPic, $swaterPic, $picInfo[0] - $waterPicInfo[0], $picInfo[1] - $waterPicInfo[1], 0, 0, $waterPicInfo[0], $waterPicInfo[1], $this->waterPct);
     imagedestroy($swaterPic);
     switch ($picInfo[2]) {
         case 1:
             imagegif($newPic, $pic);
             break;
         case 2:
             imagejpeg($newPic, $pic);
             break;
         case 3:
             imagepng($newPic, $pic);
             break;
         case 6:
             imagexbm($newPic, $pic);
             break;
     }
     imagedestroy($newPic);
 }
コード例 #13
0
ファイル: tmnick.class.php プロジェクト: keverage/adminserv
 /**
  * Affiche l'image correspondant à la ressource dans le format souhaité
  *
  * @param ressource $im ressource de l'image
  * @param string $type type de l'image de sortie
  * @return bool
  */
 private static function _getImageFromRessource($im, $type)
 {
     if (($imgtype = self::_isSupportedImageType($type)) !== false) {
         header('Content-type:' . image_type_to_mime_type($imgtype) . ';');
         switch ($imgtype) {
             case IMG_GIF:
                 return imagegif($im);
                 break;
             case IMG_JPG:
             case IMG_JPEG:
                 return imagejpeg($im);
                 break;
             case IMG_PNG:
                 return imagepng($im);
                 break;
             case IMG_WBMP:
                 return imagewbmp($im);
                 break;
             case IMG_XPM:
                 return imagexbm($im);
                 break;
         }
     }
     header('Content-type:' . image_type_to_mime_type(IMG_PNG) . ';');
     return imagepng(self::_getErrorRessource('Le format "' . $type . '" n\'est pas supporté.'));
 }
コード例 #14
0
 protected function _types()
 {
     $type = strtolower($this->type);
     if (!empty($this->save)) {
         $save = suffix($this->save, '.' . $type);
         $this->result['path'] = $save;
     } else {
         $save = NULL;
     }
     if ($type === 'jpeg') {
         if ($this->quality === 0) {
             $this->quality = 80;
         }
         imagejpeg($this->canvas, $save, $this->quality);
     } elseif ($type === 'png') {
         if ($this->quality === 0) {
             $this->quality = 8;
         }
         imagepng($this->canvas, $save, $this->quality);
     } elseif ($type === 'gif') {
         imagegif($this->canvas, $save);
     } elseif ($type === 'gd') {
         imagegd($this->canvas, $save);
     } elseif ($type === 'gd2') {
         imagegd2($this->canvas, $save, $this->quality);
     } elseif ($type === 'wbmp') {
         imagewbmp($this->canvas, $save, $this->quality);
     } elseif ($type === 'xbm') {
         imagexbm($this->canvas, $save, $this->quality);
     } elseif ($type === 'xpm') {
         imagexpm($this->canvas, $save, $this->quality);
     } elseif ($type === 'webp') {
         imagewebp($this->canvas, $save, $this->quality);
     }
     return $this;
 }
コード例 #15
0
ファイル: DrawImage.php プロジェクト: rajibmp/imager
 /**
  * Prints the Image
  * 
  * @param string $name
  * @param string $directory
  * @param string $imageType
  */
 private function saveImage($name, $directory, $imageType = 'png', $foreground = null)
 {
     switch ($imageType) {
         case 'jpg':
         case 'jpeg':
             imagejpeg($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gif':
             imagegif($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gd':
             imagegd($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'gd2':
             imagegd2($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'webp':
             imagewebp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
             break;
         case 'wbmp':
             imagewbmp($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground);
             break;
         case 'xbm':
             imagexbm($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType, $foreground);
             break;
         case 'svg':
         default:
             imagepng($this->imageProperties[0], $directory . DIRECTORY_SEPARATOR . $name . '.' . $imageType);
     }
     imagedestroy($this->imageProperties[0]);
 }
コード例 #16
0
ファイル: YCaptcha.php プロジェクト: sm115/SYFramework
 /**
  * 输出图像
  * @access public
  * @param string $type 图像格式,可选:png,gif,jpg,wbmp,webp,xbm
  * 注意:webp需要php>=5.5
  */
 public function show($type = 'png')
 {
     switch ($type) {
         case 'png':
             imagepng($this->im);
             break;
         case 'gif':
             imagegif($this->im);
             break;
         case 'jpg':
             imagejpeg($this->im);
             break;
         case 'wbmp':
             imagewbmp($this->im);
             break;
         case 'webp':
             imagewebp($this->im);
             break;
         case 'xbm':
             imagexbm($this->im);
             break;
     }
 }
コード例 #17
0
ファイル: CDImage.php プロジェクト: rainsongsky/24beta
 /**
  * 将图像保存为xbm类型
  * @param string $filename 图片文件路径,不带扩展名
  * @param integer $foreground 前景色,取值为imagecolorallocate()的返回的颜色标识符
  * @param integer $mode 图像文件的权限
  * @return CdImage CdImage对象本身
  */
 public function saveAsXbm($filename, $foreground = 0, $mode = null)
 {
     $filename .= image_type_to_extension(IMAGETYPE_XBM);
     if (!imagexbm($this->_image, $filename, $foreground)) {
         return false;
     }
     $this->_lastSaveFile = $filename;
     if ($mode !== null) {
         chmod($filename, $mode);
     }
     return $this;
 }
コード例 #18
0
ファイル: Image.php プロジェクト: rguedes/axiscommerce
 /**
  * Write resource image to filename
  *
  * @param string $filename
  * @return void
  * @throws Axis_Exception if unsupported image format recieved
  */
 public function output($filename)
 {
     switch ($this->_fileType) {
         case IMAGETYPE_GIF:
             imagegif($this->_imageResource, $filename);
             break;
         case IMAGETYPE_JPEG:
             imagejpeg($this->_imageResource, $filename);
             break;
         case IMAGETYPE_PNG:
             imagepng($this->_imageResource, $filename);
             break;
         case IMAGETYPE_XBM:
             imagexbm($this->_imageResource, $filename);
             break;
         case IMAGETYPE_WBMP:
             imagewbmp($this->_imageResource, $filename);
             break;
         default:
             throw new Axis_Exception(Axis::translate('core')->__('Unsupported image format recieved'));
             break;
     }
 }
コード例 #19
0
ファイル: PThumb.lib.php プロジェクト: firstcoder55/Webkey
 /**
  * Prints out and cache the thumbnail. Returns verbose errors.
  * 
  * @access public
  * @param string $image The Relative Path to the image
  * @param integer $width The Width of the new thumbnail
  * @param integer $height The Height of the thumbnail
  * @param boolean $return_img Set to true to return the string instead of outputting it. Default to false
  * @param boolean $display_inline If set to true, heaers sent to browser will instruct it to display the image inline instead of asking the user to download. Defaults to true.
  * @return string
  * 
  */
 function print_thumbnail($image, $width, $height, $return_img = false, $display_inline = true)
 {
     //Check parameters
     if (empty($image) || empty($width) || empty($height)) {
         return $this->set_error("Method print_thumbnail: Missing Parameters");
     }
     //Check whether $image is a remote address
     if ($this->is_remote($image) == 1) {
         $is_remote = true;
         //Check that file exists (Check only enabled in PHP 5 because only PHP 5 supports for checking remote files
         if (phpversion() >= 5) {
             if (!file_exists($image)) {
                 return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
             }
         }
         $image_data = $this->retrieve_remote_file($image, true, false, 1);
     } elseif ($this->is_remote($image) == 0) {
         $is_remote = false;
         if (!file_exists($image)) {
             return $this->set_error("Method print_thumbnail: Error. The file '{$image}' you specified does not exists or cannot be accessed.");
         }
         $image_data = @join(file($image));
     }
     if (!is_string($image_data)) {
         return $this->set_error("Method print_thumbnail: Error, could not read image file '{$image}'.");
     }
     $array = $this->retrieve_image_data($image);
     if (!$array) {
         return $this->set_error("Method print_thumbnail: Unable to determine Image '{$image}' type and/or dimensions.");
     }
     list($ori_width, $ori_height, $format) = $array;
     //Check whether format is supported
     if (!array_key_exists($format, $this->file_ext)) {
         return $this->set_error("Method print_thumbnail: Image '{$image}' format is not supported.");
     }
     //Check that cache is enabled, cache DIR is writable, cache DIR exists
     if ($this->is_cacheable()) {
         //Passed eh? Generate the root dir of request file
         if ($is_remote != true) {
             $transformed = realpath($image);
             $hash = sha1_file($image);
         } else {
             $transformed = $image;
             $hash = sha1($image_data);
         }
         //Check if a version exists
         $cache_file = $this->cache_dir . sha1($transformed) . "." . $width . "." . $height . "." . $hash . "." . $this->file_ext[$format];
         if (file_exists($cache_file)) {
             if ($return_img == false) {
                 //die($cache_file);
                 header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
                 header("Cache-Control: no-store, no-cache, must-revalidate");
                 header("Pragma: no-cache");
                 header("Content-Transfer-Encoding: binary");
                 header("Content-type: " . image_type_to_mime_type($format));
                 if ($display_inline == true) {
                     header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 } else {
                     header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
                 }
                 print join(file($cache_file));
                 die;
                 //Prepare redirectional URL
                 $redir_url = $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]) . "/" . $cache_file;
                 //Remove instances of double slashes "//"
                 $redir_url = str_replace("//", "/", $redir_url);
                 header("Location: http://{$redir_url}");
                 die;
             } else {
                 return join(file($cache_file));
             }
         } else {
             if ($handle = @opendir($this->cache_dir)) {
                 while (false !== ($file = readdir($handle))) {
                     if (preg_match("/^" . preg_quote(sha1($transformed)) . "\\.[0-9]+\\.[0-9]+\\.([0-9a-z]{40})\\.(.+?)\$/i", $file, $matches)) {
                         //Hash is in [1]
                         //Check to see if the file data is the same. If it is, then don't delete it.
                         if ($matches[1] != $hash) {
                             $matched[] = $file;
                         }
                     }
                 }
                 closedir($handle);
                 if (!empty($matched)) {
                     for ($i = 0; $i <= count($matched) - 1; $i++) {
                         @unlink($this->cache_dir . $matched[$i]);
                     }
                 }
             }
         }
     }
     $gd_info = gd_info();
     //Special GIF handling
     if ($format == 1 && $gd_info["GIF Create Support"] != true) {
         //return $this -> set_error("Method print_thumbnail: Error, GIF support is unavaliable for PHP Version ".phpversion());
         //Image Outputted will be in PNG Format
         $format = 3;
     }
     $handle = @imagecreatefromstring($image_data);
     if ($handle == false) {
         return $this->set_error("Method print_thumbnail: Unsupported Image '{$image}' type");
     }
     //Now lets resize it
     //First lets create a new image handler which will be the thumbnailed image
     $thumbnail = imagecreatetruecolor($width, $height);
     if (!$thumbnail) {
         return $this->set_error("Method print_thumbnail: A thumbnail image '{$image}' could not be created");
     }
     /*  Image Format Special Handlinng */
     //GIF truecolour to palette - preserve transparency
     if ($format == 1) {
         imagetruecolortopalette($handle, true, 256);
     }
     //PNG Alpha Channel saving
     if ($format == 3) {
         //Set to save alpha channel info in source and destination
         imagealphablending($handle, false);
         imagesavealpha($handle, true);
         imagealphablending($thumbnail, false);
         imagesavealpha($thumbnail, true);
     }
     //Resize it
     if (!$this->fastimagecopyresampled($thumbnail, $handle, 0, 0, 0, 0, $width, $height, ImageSX($handle), ImageSY($handle), $this->thumb_quality)) {
         return $this->set_error("Method print_thumbnail: Failed resizing image '{$image}'.");
     }
     //Cache it
     if ($this->is_cacheable()) {
         switch ($format) {
             case 1:
                 $cached = @imagegif($thumbnail, $cache_file);
                 break;
             case 2:
                 $cached = @imageJPEG($thumbnail, $cache_file, 100);
                 break;
             case 3:
                 $cached = @imagepng($thumbnail, $cache_file);
                 break;
             case 15:
                 $cached = @imagewbmp($thumbnail, $cache_file);
                 break;
             case 16:
                 $cached = @imagexbm($thumbnail, $cache_file);
                 break;
             default:
                 $cached = false;
         }
         if (!$cached) {
             return $this->set_error("Method print_thumbnail: Error in cache generation of image '{$image}'.");
         }
     }
     if ($return_img == false) {
         header("Expires: " . gmdate("D, d M Y H:i:s") . " GMT");
         header("Cache-Control: no-store, no-cache, must-revalidate");
         header("Pragma: no-cache");
         header("Content-Transfer-Encoding: binary");
         header("Content-type: " . image_type_to_mime_type($format));
         if ($display_inline == true) {
             header("Content-Disposition: inline; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         } else {
             header("Content-Disposition: attachment; filename=\"" . time() . "." . $this->file_ext[$format] . "\"");
         }
         if ($this->is_cacheable()) {
             echo join(file($cache_file));
         } else {
             switch ($format) {
                 case 1:
                     $outputed = @imagegif($thumbnail);
                     break;
                 case 2:
                     $outputed = @imageJPEG($thumbnail, '', 100);
                     break;
                 case 3:
                     $outputed = @imagepng($thumbnail);
                     break;
                 case 15:
                     $outpupted = @imagewbmp($thumbnail);
                     break;
                 case 16:
                     $outputed = @imagexbm($thumbnail);
                     break;
                 default:
                     $outputed = false;
             }
             if (!$outputed) {
                 return $this->set_error("Method print_thumbnail: Error outputting Image '{$image}'");
             }
         }
     } else {
         if ($this->is_cacheable()) {
             return join(file($cache_file));
         } else {
             return $this->set_error("Method print_thumbnail: Cannot return image '{$image}'! Cache must be enabled!");
         }
     }
     //Destroy the image
     imagedestroy($handle);
     imagedestroy($thumbnail);
     //Clear any cache; if needed
     $this->clear_cache();
 }
コード例 #20
0
ファイル: coloreidting.php プロジェクト: benjaco/fileeater
        $img = imagecreatefromjpeg($fil);
        $new_image_ext = 'jpg';
}
if ($sorthvid == "1") {
    imagefilter($img, IMG_FILTER_GRAYSCALE);
}
imagefilter($img, IMG_FILTER_BRIGHTNESS, $lysbalance);
imagefilter($img, IMG_FILTER_CONTRAST, $kontrast);
switch ($type) {
    case 'jpeg':
        imagejpeg($img, $fil);
        break;
    case 'png':
        imagepng($img, $fil);
        break;
    case 'bmp':
        imagebmp($img, $fil);
        break;
    case 'gif':
        imagegif($img, $fil);
        break;
    case 'vnd.wap.wbmp':
        imagewbmp($img, $fil);
        break;
    case 'xbm':
        imagexbm($img, $fil);
        break;
    default:
        imagejpeg($img, $fil);
}
imagedestroy($img);
コード例 #21
0
ファイル: Gd2.php プロジェクト: arslbbt/mangentovies
 public function display()
 {
     header("Content-type: " . $this->getMimeType());
     switch ($this->_fileType) {
         case IMAGETYPE_GIF:
             imagegif($this->_imageHandler);
             break;
         case IMAGETYPE_JPEG:
             imagejpeg($this->_imageHandler);
             break;
         case IMAGETYPE_PNG:
             imagepng($this->_imageHandler);
             break;
         case IMAGETYPE_XBM:
             imagexbm($this->_imageHandler);
             break;
         case IMAGETYPE_WBMP:
             imagewbmp($this->_imageHandler);
             break;
         default:
             throw new Exception("Unsupported image format.");
             break;
     }
 }
コード例 #22
0
ファイル: crop.php プロジェクト: Blu2z/implsk
 /**
  * Save image in to file
  * @access public
  * @param  resource $image       - gd image resource
  * @param  string   $destination - output destination path and filename
  * @param  string   $prefix      - prefix to the file name
  * @param  string   $type        - new image format (default = png)
  * @param  int      $quality     - resulted image quality (default = 100)
  * @return string path to destination
  */
 public static function save($image, $destination, $prefix = '', $type = 'png', $quality = 100)
 {
     $type = strtolower($type);
     # build new image name
     //if($prefix || $type) {
     //if($type != '' || $prefix != '') {
     //    $destination = self::buildimagename($destination,$prefix,$type);
     //}
     //}
     if (self::isgdresource($image)) {
         switch ($type) {
             case 'gif':
                 imagegif($image, $destination);
                 break;
             case 'jpg':
             case 'jpeg':
                 imagejpeg($image, $destination, $quality);
                 break;
             case 'png':
                 imagepng($image, $destination);
                 break;
             case 'wbmp':
                 imagewbmp($image, $destination);
                 break;
             case 'xbm':
                 imagexbm($image, $destination);
                 break;
             default:
                 echo 'Unsupported image file format.';
         }
     } else {
         $destination = false;
     }
     return $destination;
 }
コード例 #23
0
 /**
  * 顯示輸出圖像
  * @return void
  */
 public function display($fileName = '', $quality = 100)
 {
     $imgType = $this->newResType;
     $imageSrc = $this->newResource;
     switch ($imgType) {
         case IMAGETYPE_GIF:
             if ($fileName == '') {
                 header('Content-type: image/gif');
             }
             imagegif($imageSrc, $fileName, $quality);
             break;
         case IMAGETYPE_JPEG:
             if ($fileName == '') {
                 header('Content-type: image/jpeg');
             }
             imagejpeg($imageSrc, $fileName, $quality);
             break;
         case IMAGETYPE_PNG:
             if ($fileName == '') {
                 header('Content-type: image/png');
                 imagepng($imageSrc);
             } else {
                 imagepng($imageSrc, $fileName);
             }
             break;
         case IMAGETYPE_WBMP:
             if ($fileName == '') {
                 header('Content-type: image/wbmp');
             }
             imagewbmp($imageSrc, $fileName, $quality);
             break;
         case IMAGETYPE_XBM:
             if ($fileName == '') {
                 header('Content-type: image/xbm');
             }
             imagexbm($imageSrc, $fileName, $quality);
             break;
         default:
             throw new Exception('Unsupport image type');
     }
     imagedestroy($imageSrc);
 }
コード例 #24
0
ファイル: ConvertImages.php プロジェクト: Nolfneo/docvert
 function saveImageByResource($imageResource, $toImagePath, $toFormat)
 {
     switch ($toFormat) {
         // these imagegif function calls are builtin. See http://php.net/imagegif , for example.
         case 'gif':
             //TODO: ensure GIF transparency is maintained. See notes on php.net/imagegif
             imagegif($imageResource, $toImagePath);
             break;
         case 'jpg':
         case 'jpeg':
             imagejpeg($imageResource, $toImagePath, $jpegQuality);
             break;
         case 'png':
             //TODO: ensure PNG transparency is maintained. See notes on php.net/imagepng
             imagepng($imageResource, $toImagePath);
             break;
         case 'xbm':
             imagexbm($imageResource, $toImagePath);
             break;
         case 'xpm':
             webServiceError('&error-process-convertimages-no-xpm;');
             break;
         default:
             webServiceError('&error-process-convertimages-unsupported-image;', 500, array('toFormat' => $toFormat));
     }
 }
コード例 #25
0
ファイル: image.php プロジェクト: hjimmy/owncloud
 /**
  * @brief Outputs/saves the image.
  */
 private function _output($filePath = null, $mimeType = null)
 {
     if ($filePath) {
         if (!file_exists(dirname($filePath))) {
             mkdir(dirname($filePath), 0777, true);
         }
         if (!is_writable(dirname($filePath))) {
             OC_Log::write('core', __METHOD__ . '(): Directory \'' . dirname($filePath) . '\' is not writable.', OC_Log::ERROR);
             return false;
         } elseif (is_writable(dirname($filePath)) && file_exists($filePath) && !is_writable($filePath)) {
             OC_Log::write('core', __METHOD__ . '(): File \'' . $filePath . '\' is not writable.', OC_Log::ERROR);
             return false;
         }
     }
     if (!$this->valid()) {
         return false;
     }
     $imageType = $this->imageType;
     if ($mimeType !== null) {
         switch ($mimeType) {
             case 'image/gif':
                 $imageType = IMAGETYPE_GIF;
                 break;
             case 'image/jpeg':
                 $imageType = IMAGETYPE_JPEG;
                 break;
             case 'image/png':
                 $imageType = IMAGETYPE_PNG;
                 break;
             case 'image/x-xbitmap':
                 $imageType = IMAGETYPE_XBM;
                 break;
             case 'image/bmp':
                 $imageType = IMAGETYPE_BMP;
                 break;
             default:
                 throw new Exception('\\OC_Image::_output(): "' . $mimeType . '" is not supported when forcing a specific output format');
         }
     }
     switch ($imageType) {
         case IMAGETYPE_GIF:
             $retVal = imagegif($this->resource, $filePath);
             break;
         case IMAGETYPE_JPEG:
             $retVal = imagejpeg($this->resource, $filePath);
             break;
         case IMAGETYPE_PNG:
             $retVal = imagepng($this->resource, $filePath);
             break;
         case IMAGETYPE_XBM:
             if (function_exists('imagexbm')) {
                 $retVal = imagexbm($this->resource, $filePath);
             } else {
                 throw new Exception('\\OC_Image::_output(): imagexbm() is not supported.');
             }
             break;
         case IMAGETYPE_WBMP:
             $retVal = imagewbmp($this->resource, $filePath);
             break;
         case IMAGETYPE_BMP:
             $retVal = imagebmp($this->resource, $filePath, $this->bitDepth);
             break;
         default:
             $retVal = imagepng($this->resource, $filePath);
     }
     return $retVal;
 }
コード例 #26
0
 private function generateThumbnail($source, $destination, $width, $height)
 {
     $imagetype = exif_imagetype($source);
     switch ($imagetype) {
         case IMAGETYPE_JPEG:
             $img = imagecreatefromjpeg($source);
             break;
         case IMAGETYPE_PNG:
             $img = imagecreatefrompng($source);
             break;
         case IMAGETYPE_GIF:
             $img = imagecreatefromgif($source);
             break;
         case IMAGETYPE_WBMP:
             $img = imagecreatefromwbmp($source);
             break;
         case IMAGETYPE_XBM:
             $img = imagecreatefromxbm($source);
             break;
         default:
             throw new \RuntimeException(sprintf('Unknown image type for file "%s"', $source));
             break;
     }
     $sourceWidth = imagesx($img);
     $sourceHeight = imagesy($img);
     $height = floor($sourceHeight * ($width / $sourceWidth));
     $tmp = imagecreatetruecolor($width, $height);
     imageantialias($tmp, true);
     imagecopyresized($tmp, $img, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight);
     if (!file_exists(dirname($destination))) {
         mkdir(dirname($destination), 0755, true);
         chmod(dirname($destination), 0755);
     }
     imagedestroy($img);
     switch ($imagetype) {
         case IMAGETYPE_JPEG:
             imagejpeg($tmp, $destination);
             break;
         case IMAGETYPE_PNG:
             imagepng($tmp, $destination);
             break;
         case IMAGETYPE_GIF:
             imagegif($tmp, $destination);
             break;
         case IMAGETYPE_WBMP:
             imagewbmp($tmp, $destination);
             break;
         case IMAGETYPE_XBM:
             imagexbm($tmp, $destination);
             break;
         default:
             throw new \RuntimeException(sprintf('Unknown image type for file "%s"', $source));
             break;
     }
     imagedestroy($tmp);
 }