save() 공개 메소드

This function will make sure the target directory is writeable, and then save the image. If the target directory is not writeable, the function will try to correct the permissions (if allowed, this is set as an option ($this->options['correctPermissions']). If the target cannot be made writeable, then a RuntimeException is thrown. TODO: Create additional paramter for color matte when saving images with alpha to non-alpha formats (i.e. PNG => JPG)
public save ( string $fileName, string $format = null ) : GdThumb
$fileName string The full path and filename of the image to save
$format string The format to save the image in (optional, must be one of [GIF,JPG,PNG]
리턴 GdThumb
예제 #1
0
 protected function _writeResized(GdThumb $resized, $type = null)
 {
     $resized->save($this->getOutputPath(), $type);
     return $this->getOutputPath();
 }
예제 #2
0
 public static function createThumb($source, $dest = null, $width = 200, $height = 160, $mode = 'resize')
 {
     if (!class_exists('ThumbBase')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/ThumbBase.inc.php';
     }
     if (!class_exists('GdThumb')) {
         require_once JPATH_SITE . '/plugins/system/jvhelper/libs/GdThumb.inc.php';
     }
     if (!$dest) {
         $dest = JPATH_SITE . '/images/jvthumb';
     }
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$height}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         $thumb = new GdThumb($source, array('jpegQuality' => 80));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }
예제 #3
0
파일: helper.php 프로젝트: khiconit/sdvico
 public static function createThumb($source, $dest, $width, $height, $mode)
 {
     $size = @getimagesize($source);
     if (!is_array($size)) {
         return $source;
     }
     $replace = JURI::base(true) . '/';
     if (strpos($source, $replace) === 0) {
         $source = substr($source, strlen($replace));
     }
     if (preg_match('#http(s?):\\/\\/#', $source) && $source) {
         if (stripos($size['mime'], 'image') === 0) {
             $extension = substr($size['mime'], 6);
             if ($extension == 'jpeg') {
                 $extension = 'jpg';
             }
             $info = array('extension' => $extension, 'filename' => substr(base64_encode(json_encode($size)), 0, 10));
         } else {
             return $source;
         }
     } else {
         $source = JPATH_SITE . '/' . $source;
         $info = pathinfo($source);
     }
     // Resize path
     $path = $dest . "/{$mode}_{$width}_{$info['filename']}.{$info['extension']}";
     if (!is_dir(dirname($path))) {
         JFolder::create(dirname($path));
         $index = "<html><body></body></html>";
         if (!JFile::write($path . '/' . 'index.html', $index)) {
             return;
         }
     }
     if (!is_file($path)) {
         // Resize
         if ($mode == 'original') {
             JFile::copy($source, $path);
             return self::toURL($path);
         }
         $thumb = new GdThumb($source, array('jpegQuality' => 90));
         if ($mode == 'resize') {
             $thumb->resize($width, $height);
         }
         if ($mode == 'crop') {
             $thumb->cropFromCenter($width, $height);
         }
         $thumb->save($path, $info['extension']);
     }
     return self::toURL($path);
 }