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)
protected function _writeResized(GdThumb $resized, $type = null) { $resized->save($this->getOutputPath(), $type); return $this->getOutputPath(); }
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); }
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); }