public function generateRotateAuto(GD $gd) { $exif = $this->Exif(); if (!$exif) { return; } $imagePath = $this->owner->getFullPath(); $imageFileExt = strtolower(File::get_file_extension($imagePath)); if (!in_array($imageFileExt, array('jpeg', 'jpg'))) { return; } $orientation = $this->getExifOrientation(); if (!$orientation) { return; } switch ($orientation) { case 3: // image upside down return $gd->rotate(180); case 6: // 90 rotate right & switch max sizes return $gd->rotate(-90); case 8: // 90 rotate left & switch max sizes return $gd->rotate(90); } return false; }
/** * Takes samples from the given GD at 5 pixel increments * @param GD $gd The source image * @param integer $horizontal Number of samples to take horizontally * @param integer $vertical Number of samples to take vertically * @return array List of colours for each sample, each given as an associative * array with red, blue, green, and alpha components */ protected function sampleAreas(GD $gd, $horizontal = 4, $vertical = 4) { $samples = array(); for ($y = 0; $y < $vertical; $y++) { for ($x = 0; $x < $horizontal; $x++) { $colour = imagecolorat($gd->getImageResource(), $x * 5, $y * 5); $samples[] = ImageColorsforIndex($gd->getImageResource(), $colour); } } return $samples; }
/** * Runs [GD::check] and loads the image. * * @param string $file image file path * @return void */ public function __construct($file) { if (!GD::$_checked) { // Run the install check GD::check(); } parent::__construct($file); // Set the image creation function name switch ($this->type) { case IMAGETYPE_JPEG: $create = 'imagecreatefromjpeg'; break; case IMAGETYPE_GIF: $create = 'imagecreatefromgif'; break; case IMAGETYPE_PNG: $create = 'imagecreatefrompng'; break; } if (!isset($create) or !function_exists($create)) { die('Installed GD does not support ' . image_type_to_extension($this->type, FALSE) . ' images'); } // Save function for future use $this->_create_function = $create; // Save filename for lazy loading $this->_image = $this->file; }
/** * Resamples the image to the maximum Height and Width */ public function resampleImage() { $extension = strtolower($this->owner->getExtension()); if ($this->owner->getHeight() > $this->getMaxX() || $this->owner->getWidth() > $this->getMaxY()) { $original = $this->owner->getFullPath(); $resampled = $original . '.tmp.' . $extension; $gd = new GD($original); if ($gd->hasImageResource()) { $gd = $gd->resizeRatio($this->getMaxX(), $this->getMaxY()); if ($gd) { $gd->writeTo($resampled); unlink($original); rename($resampled, $original); } } } }
/** * @brief 生成缩略图 * @param string $fileName 原图路径 * @param int $width 缩略图的宽度 * @param int $height 缩略图的高度 * @param string $extName 缩略图文件名附加值 * @param string $saveDir 缩略图存储目录 * @return string 缩略图文件名 */ public static function thumb($fileName, $width = 200, $height = 200, $extName = '_thumb', $saveDir = '') { $GD = new GD($fileName); if ($GD) { $GD->resize($width, $height); $GD->pad($width, $height); //存储缩略图 if ($saveDir && IFile::mkdir($saveDir)) { //生成缩略图文件名 $thumbBaseName = $extName . basename($fileName); $thumbFileName = $saveDir . basename($thumbBaseName); $GD->save($thumbFileName); return $thumbFileName; } else { return $GD->show(); } } return null; }
public function ScaleUpload() { /* don't use Image->exists() as it is implemented differently for Image */ if ($this->owner->ID > 0 || $this->getBypass()) { return; // only run with new images } $extension = $this->owner->getExtension(); if ($this->owner->getHeight() > $this->getMaxHeight() || $this->owner->getWidth() > $this->getMaxWidth() || $this->getAutoRotate() && preg_match('/jpe?g/i', $extension)) { $original = $this->owner->getFullPath(); /* temporary location for image manipulation */ $resampled = TEMP_FOLDER . '/resampled-' . mt_rand(100000, 999999) . '.' . $extension; $gd = new GD($original); /* Backwards compatibility with SilverStripe 3.0 */ $image_loaded = method_exists('GD', 'hasImageResource') ? $gd->hasImageResource() : $gd->hasGD(); if ($image_loaded) { /* Clone original */ $transformed = $gd; /* If rotation allowed & JPG, test to see if orientation needs switching */ if ($this->getAutoRotate() && preg_match('/jpe?g/i', $extension)) { $switch_orientation = $this->exifRotation($original); if ($switch_orientation) { $transformed = $transformed->rotate($switch_orientation); } } /* Resize to max values */ if ($transformed && ($transformed->getWidth() > $this->getMaxWidth() || $transformed->getHeight() > $this->getMaxHeight())) { $transformed = $transformed->resizeRatio($this->getMaxWidth(), $this->getMaxHeight()); } /* Write to tmp file and then overwrite original */ if ($transformed) { $transformed->writeTo($resampled); file_put_contents($original, file_get_contents($resampled)); unlink($resampled); } } } }
<?php //Bootstrap SPF require 'includes/master.inc.php'; // Set the headers so the image gets created header("Content-type:image/jpeg"); // Lets check if we should be creating a image and we will only be able to do specific types if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'captcha') { header("Content-Disposition:inline ;filename=captcha.jpg"); Captcha::createImage(100, 50, 5); } // Wallpaper request, I will decide later if we will be allowing only registered users to download if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'get_wallpaper' && isset($_REQUEST['width']) && !empty($_REQUEST['width']) && isset($_REQUEST['height']) && !empty($_REQUEST['height']) && isset($_REQUEST['img']) && !empty($_REQUEST['img'])) { $img = new GD(); set_time_limit(3600); $imgSaveName = str_replace('.jpg', "_wallpaper_" . $_REQUEST['width'] . "_" . $_REQUEST['height'] . ".jpg", $_REQUEST['img']); header("Content-Disposition:inline ;filename=" . $imgSaveName); $img->resizeToResolution($_REQUEST['img'], $_REQUEST['width'], $_REQUEST['height']); }
public function __construct() { parent::__construct(); $this->setName('Renderer'); $this->addTest(GD::suite()); }
/** * Generate an image on the specified format. It will save the image * at the location specified by cacheFilename(). The image will be generated * using the specific 'generate' method for the specified format. * @param string $format Name of the format to generate. * @param string $arg1 Argument to pass to the generate method. * @param string $arg2 A second argument to pass to the generate method. */ function generateFormattedImage($format, $arg1 = null, $arg2 = null) { $cacheFile = $this->cacheFilename($format, $arg1, $arg2); $gd = new GD(Director::baseFolder() . "/" . $this->Filename); if ($gd->hasGD()) { $generateFunc = "generate{$format}"; if ($this->hasMethod($generateFunc)) { $gd = $this->{$generateFunc}($gd, $arg1, $arg2); if ($gd) { $gd->writeTo(Director::baseFolder() . "/" . $cacheFile); } } else { user_error("Image::generateFormattedImage - Image {$format} function not found.", E_USER_WARNING); } } }
/** * Make the image greyscale * $rv = red value, defaults to 38 * $gv = green value, defaults to 36 * $bv = blue value, defaults to 26 * Based (more or less entirely, with changes for readability) on code from http://www.teckis.com/scriptix/thumbnails/teck.html */ function greyscale($rv = 38, $gv = 36, $bv = 26) { $width = $this->width; $height = $this->height; $newGD = imagecreatetruecolor($this->width, $this->height); $rt = $rv + $bv + $gv; $rr = $rv == 0 ? 0 : 1 / ($rt / $rv); $br = $bv == 0 ? 0 : 1 / ($rt / $bv); $gr = $gv == 0 ? 0 : 1 / ($rt / $gv); for ($dy = 0; $dy <= $height; $dy++) { for ($dx = 0; $dx <= $width; $dx++) { $pxrgb = imagecolorat($this->gd, $dx, $dy); $heightgb = ImageColorsforIndex($this->gd, $pxrgb); $newcol = $rr * $heightgb['red'] + $br * $heightgb['blue'] + $gr * $heightgb['green']; $setcol = ImageColorAllocate($newGD, $newcol, $newcol, $newcol); imagesetpixel($newGD, $dx, $dy, $setcol); } } // imagecopyresampled($newGD, $this->gd, 0,0, $srcX, $srcY, $width, $height, $srcWidth, $srcHeight); $output = new GD(); $output->setGD($newGD); if ($this->quality) { $output->setQuality($this->quality); } return $output; }
public function generateRotatedImage(GD $gd, $angle) { return $gd->rotate($angle); }
$project = 'mysite'; global $databaseConfig; $databaseConfig = array("type" => 'MySQLDatabase', "server" => 'localhost', "username" => 'root', "password" => 'omega', "database" => 'vp', "path" => ''); MySQLDatabase::set_connection_charset('utf8'); // Set the current theme. More themes can be downloaded from // http://www.silverstripe.org/themes/ SSViewer::set_theme('simple'); // Set the site locale i18n::set_locale('en_US'); FulltextSearchable::enable(); // Enable nested URLs for this site (e.g. page/sub-page/) if (class_exists('SiteTree')) { SiteTree::enable_nested_urls(); } Director::set_environment_type("dev"); // add a button to remove formatting HtmlEditorConfig::get('cms')->insertButtonsBefore('styleselect', 'removeformat'); // tell the button which tags it may remove HtmlEditorConfig::get('cms')->setOption('removeformat_selector', 'b,strong,em,i,span,ins'); //remove font->span conversion HtmlEditorConfig::get('cms')->setOption('convert_fonts_to_spans', 'false,'); HtmlEditorConfig::get('cms')->setOptions(array('valid_elements' => "@[id|class|style|title],#a[id|rel|rev|dir|tabindex|accesskey|type|name|href|target|title|class],-strong/-b[class],-em/-i[class],-strike[class],-u[class],#p[id|dir|class|align|style],-ol[class],-ul[class],-li[class],br,img[id|dir|longdesc|usemap|class|src|border|alt=|title|width|height|align],-sub[class],-sup[class],-blockquote[dir|class],-table[border=0|cellspacing|cellpadding|width|height|class|align|summary|dir|id|style],-tr[id|dir|class|rowspan|width|height|align|valign|bgcolor|background|bordercolor|style],tbody[id|class|style],thead[id|class|style],tfoot[id|class|style],#td[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],-th[id|dir|class|colspan|rowspan|width|height|align|valign|scope|style],caption[id|dir|class],-h1[id|dir|class|align|style],-h2[id|dir|class|align|style],-h3[id|dir|class|align|style],-h4[id|dir|class|align|style],-h5[id|dir|class|align|style],-h6[id|dir|class|align|style],hr[class],dd[id|class|title|dir],dl[id|class|title|dir],dt[id|class|title|dir],@[id,style,class],small", 'extended_valid_elements' => "img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],#iframe[src|name|width|height|align|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt]")); // TinyMCE cleanup on paste HtmlEditorConfig::get('cms')->setOption('paste_auto_cleanup_on_paste', 'true'); HtmlEditorConfig::get('cms')->setOption('paste_remove_styles', 'true'); HtmlEditorConfig::get('cms')->setOption('paste_remove_styles_if_webkit', 'true'); HtmlEditorConfig::get('cms')->setOption('paste_strip_class_attributes', 'true'); GD::set_default_quality(80); ShortcodeParser::get()->register('blogfeed', array('Page_Controller', 'BlogFeedHandler')); ShortcodeParser::get()->register('spotlight', array('Page_Controller', 'StaffSpotlightHandler')); Object::add_extension("BlogEntry", "BlogFieldExtension");
/** * Get image path * * @param int/string $input * @param string $mode * @param string $path * @param bool $return_placeholder * @return string */ public function imagePath($input, $mode = 'medium', $path = 'relative', $return_placeholder = true) { foreach ($GLOBALS['hooks']->load('class.catalogue.imagepath') as $hook) { include $hook; } $defaults = true; if (is_numeric($input)) { if (($result = $GLOBALS['db']->select('CubeCart_filemanager', false, array('file_id' => (int) $input))) !== false) { $file = $result[0]['filepath'] . $result[0]['filename']; $defaults = false; } } else { if (!empty($input)) { $file = str_replace(array('images/cache/', 'images/uploads/'), '', $input); $defaults = false; } } $skins = $GLOBALS['gui']->getSkinData(); // Fetch a default image, just in case... if (is_array($mode)) { foreach ($mode as $mode_name) { if (isset($skins['images'][$mode_name])) { $mode = $mode_name; break; } } } if ($return_placeholder && isset($skins['images'][$mode])) { $default = (string) $skins['images'][$mode]['default']; if (isset($skins['styles'][$GLOBALS['gui']->getStyle()]['images']) && !empty($skins['styles'][$GLOBALS['gui']->getStyle()]['images'])) { // do we use a separate style folder for images? $files = glob('skins/' . $GLOBALS['gui']->getSkin() . '/' . 'images/{common,' . $GLOBALS['gui']->getStyle() . '}/' . $default, GLOB_BRACE); } else { $files = glob('skins/' . $GLOBALS['gui']->getSkin() . '/' . 'images/' . $default, GLOB_BRACE); } if ($files && !empty($files[0])) { $placeholder_image = $files[0]; } } if (isset($file) && !empty($file) && !preg_match('/^skins\\//', $file)) { $source = CC_ROOT_DIR . '/images/source/' . $file; } else { $source = CC_ROOT_DIR . '/' . $placeholder_image; } if (!is_dir($source) && file_exists($source)) { if ($mode == 'source') { $folder = 'source'; $filename = $file; } else { $folder = 'cache'; if (isset($skins['images'][$mode])) { $data = $skins['images'][$mode]; preg_match('#(.*)(\\.\\w+)$#', $file, $match); $size = (int) $data['maximum']; $filename = sprintf('%s.%d%s', $match[1], $size, $match[2]); ## Find the source $image = CC_ROOT_DIR . '/images/' . $folder . '/' . $filename; if (!file_exists($image)) { ## Check if the target folder exists - if not, create it! if (!file_exists(dirname($image))) { mkdir(dirname($image), chmod_writable(), true); } ## Generate the image $gd = new GD(dirname($image), $size, (int) $data['quality']); $gd->gdLoadFile($source); $gd->gdSave(basename($image)); } } else { trigger_error('No image mode set', E_USER_NOTICE); return false; } } ## Generate the required path switch (strtolower($path)) { case 'filename': ## Calculate the from source folder $img = $filename; break; case 'root': ## Calculate the absolute filesystem path $img = CC_ROOT_DIR . '/images/' . $folder . '/' . $filename; break; case 'url': ## Calculate the absolute url $img = $GLOBALS['storeURL'] . '/images/' . $folder . '/' . $filename; break; case 'rel': case 'relative': ## Calculate the relative web path $img = $GLOBALS['rootRel'] . 'images/' . $folder . '/' . $filename; break; default: trigger_error('No image path set', E_USER_NOTICE); return false; } return $img; } else { return ''; } }
<?php LeftAndMain::require_css('express/css/custom.css'); SiteTree::add_extension('ExpressSiteTree'); ContentController::add_extension('ExpressSiteTree_Controller'); SiteConfig::add_extension('CustomSiteConfig'); // Don't allow h1 in the editor HtmlEditorConfig::get('cms')->setOption('theme_advanced_blockformats', 'p,pre,address,h2,h3,h4,h5,h6'); // Add in start and type attributes for ol HtmlEditorConfig::get('cms')->setOption('extended_valid_elements', 'img[class|src|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name|usemap],iframe[src|name|width|height|title|align|allowfullscreen|frameborder|marginwidth|marginheight|scrolling],object[width|height|data|type],param[name|value],map[class|name|id],area[shape|coords|href|target|alt],ol[start|type]'); // Macrons HtmlEditorConfig::get('cms')->enablePlugins(array('ssmacron' => '../../../framework/thirdparty/tinymce_ssmacron/editor_plugin_src.js')); HtmlEditorConfig::get('cms')->insertButtonsAfter('charmap', 'ssmacron'); GD::set_default_quality(90); FulltextSearchable::enable(); // Configure document converter. if (class_exists('DocumentConverterDecorator')) { DocumentImportIFrameField_Importer::set_docvert_username('ss-express'); DocumentImportIFrameField_Importer::set_docvert_password('hLT7pCaJrYVz'); DocumentImportIFrameField_Importer::set_docvert_url('http://docvert.silverstripe.com:8888/'); Page::add_extension('DocumentConverterDecorator'); } // Default translations if (class_exists('Translatable')) { Translatable::set_default_locale('en_NZ'); Translatable::set_allowed_locales(array('en_NZ', 'mi_NZ', 'zh_cmn', 'en_GB')); SiteTree::add_extension('Translatable'); SiteConfig::add_extension('Translatable'); } Config::inst()->update('i18n', 'common_locales', array("mi_NZ" => array(0 => 'Māori'))); Config::inst()->update('i18n', 'common_languages', array("mi" => array(0 => 'Māori')));
/** * Generate an image on the specified format. It will save the image * at the location specified by cacheFilename(). The image will be generated * using the specific 'generate' method for the specified format. * @param string $format Name of the format to generate. * @param string $arg1 Argument to pass to the generate method. * @param string $arg2 A second argument to pass to the generate method. */ function generateFormattedImage($format, $arg1 = null, $arg2 = null) { $cacheFile = $this->cacheFilename($format, $arg1, $arg2); $gd = new GD("../" . $this->Filename); if($gd->hasGD()){ $generateFunc = "generate$format"; if($this->hasMethod($generateFunc)){ $gd = $this->$generateFunc($gd, $arg1, $arg2); if($gd){ $gd->writeTo("../" . $cacheFile); } } else { USER_ERROR("Image::generateFormattedImage - Image $format function not found.",E_USER_WARNING); } } }
public static function createFromConfig(array $config) { if ('gd' == $config['image.module']) { return GD::createFromConfig($config); } }
<?php define('LITECMS', basename(dirname(__FILE__))); SSViewer::set_source_file_comments(false); CMSMenu::remove_menu_item("CommentAdmin"); CMSMenu::remove_menu_item("ReportAdmin"); CMSMenu::remove_menu_item("SecurityAdmin"); CMSMenu::remove_menu_item("Help"); Object::add_extension('SiteConfig', 'LiteCMSBaseConfig'); Object::add_extension('LeftAndMain', 'LiteCMS'); Object::add_extension('SiteConfig', 'LiteCMSMaintenance'); Object::add_extension('Page', 'LiteCMSMaintenanceController_Decorator'); GD::set_default_quality(100); LeftAndMain::setApplicationName("LiteCMS"); LeftAndMain::require_css('litecms/css/lite.css'); Image::add_extension('LiteCMSImage'); File::add_extension('LiteCMSAttachment');
public function generateRotateCounterClockwise(GD $gd) { return $gd->rotate(270); }
/** * @usage can be used in a template like this $Image.LargeImage.Link * @return GD **/ function generateLargeImage(GD $gd) { $gd->setQuality(90); return $gd->resizeByWidth($this->LargeWidth()); }
* @platform CMS SilverStripe 3 * @package cwsoft-shortcode * @version 2.2.4 * @author cwsoft (http://cwsoft.de) * @copyright cwsoft * @license http://www.gnu.org/licenses/gpl-3.0.html */ // ensure module is stored in folder "cwsoft-shortcode" $moduleName = 'cwsoft-shortcode'; $folderName = basename(dirname(__FILE__)); if ($folderName != $moduleName) { user_error(_t('_config.WRONG_MODULE_FOLDER', 'Please rename the folder "{folderName}" into "{moduleName}" to get the {moduleName} module working properly.', array('moduleName' => $moduleName, 'folderName' => $folderName)), E_USER_ERROR); } // include external files into head section Requirements::set_write_js_to_body(false); // register short code tags accessible from pages of type cwsCodePage ShortcodeParser::get()->register('cwsHideMailto', array('cwsShortCodeHideMailto', 'cwsShortCodeHideMailtoHandler')); ShortcodeParser::get()->register('cwsRandomImage', array('cwsShortCodeRandomImage', 'cwsShortCodeRandomImageHandler')); ShortcodeParser::get()->register('cwsRandomQuote', array('cwsShortCodeRandomQuote', 'cwsShortCodeRandomQuoteHandler')); // increase quality of created thumbnails if (class_exists('GDBackend')) { // SilverStripe >= 3.1.0 GDBackend::set_default_quality(95); } else { // SilverStripe 3.0.x GD::set_default_quality(95); } // Note: If you see unparsed placeholders like "{#shortcode.dlg_description}" when using the TinyMCE cwsoft-shortcode plugin, // you need to add a plugin language file for your locale to the folder "./plugins/shortcode/langs". Supported locales: EN, DE. HtmlEditorConfig::get('cms')->enablePlugins(array('shortcode' => '../../../cwsoft-shortcode/plugins/shortcode/editor_plugin_src.js')); HtmlEditorConfig::get('cms')->addButtonsToLine(1, 'shortcode');
public function __construct() { parent::__construct(); $this->setName('MetaImage'); $this->addTest(GD::suite()); }
public function generateMediumSizeImage(GD $gd) { return $gd->resizeByWidth($this->MediumWidth); }
/** * Resize to fit fully within the given box, without resizing. Extra space left around * the image will be padded with the background color. * @param width * @param height * @param backgroundColour */ public function paddedResize($width, $height, $backgroundColor = "FFFFFF") { if (!$this->gd) { return; } $width = round($width); $height = round($height); // Check that a resize is actually necessary. if ($width == $this->width && $height == $this->height) { return $this; } $newGD = imagecreatetruecolor($width, $height); // Preserves transparency between images imagealphablending($newGD, false); imagesavealpha($newGD, true); $bg = GD::color_web2gd($newGD, $backgroundColor); imagefilledrectangle($newGD, 0, 0, $width, $height, $bg); $destAR = $width / $height; if ($this->width > 0 && $this->height > 0) { // We can't divide by zero theres something wrong. $srcAR = $this->width / $this->height; // Destination narrower than the source if ($destAR > $srcAR) { $destY = 0; $destHeight = $height; $destWidth = round($height * $srcAR); $destX = round(($width - $destWidth) / 2); // Destination shorter than the source } else { $destX = 0; $destWidth = $width; $destHeight = round($width / $srcAR); $destY = round(($height - $destHeight) / 2); } imagecopyresampled($newGD, $this->gd, $destX, $destY, 0, 0, $destWidth, $destHeight, $this->width, $this->height); } $output = clone $this; $output->setImageResource($newGD); return $output; }
/** * Method return JSON array containing info about image. * * @param gd - GD object used for retrieving info about image * @param file * * @return string JSON array explained in manipulate method comment */ private function getImageInfoInJSON(GD $gd,$file) { return '{"fileName":"' . $file . '","width":' . $gd->getWidth() . ',"height":' . $gd->getHeight() . '}'; }
/** * Generate an image on the specified format. It will save the image * at the location specified by cacheFilename(). The image will be generated * using the specific 'generate' method for the specified format. * @param string $format Name of the format to generate. * @param string $arg1 Argument to pass to the generate method. * @param string $arg2 A second argument to pass to the generate method. */ function generateFormattedImage($format, $arg1 = null, $arg2 = null) { $cacheFile = $this->cacheFilename($format, $arg1, $arg2); $gd = new GD($this->URL); if ($gd->hasGD()) { $generateFunc = "generate{$format}"; if ($this->hasMethod($generateFunc)) { $gd = $this->{$generateFunc}($gd, $arg1, $arg2); if ($gd) { $bucket = $this->getUploadBucket(); // TODO create bucket if it does not exist // $this->S3->putBucket($bucket, S3::ACL_PUBLIC_READ); $tempFile = tempnam(getTempFolder(), 's3images') . File::get_file_extension($cacheFile); $gd->writeTo($tempFile); $this->S3->putObjectFile($tempFile, $bucket, '_resampled/' . basename($cacheFile), S3::ACL_PUBLIC_READ); unlink($tempFile); } } else { USER_ERROR("Image::generateFormattedImage - Image {$format} function not found.", E_USER_WARNING); } } }
/** * Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio and focus point. * Use in templates with $CropboxImage * * @param GD $gd * @param integer $width Width to crop to * @param integer $height Height to crop to * @return GD */ public function generateCropboxedImage(GD $gd, $width, $height) { $width = round($width); $height = round($height); // Check that a resize is actually necessary. if ($width == $this->owner->Width && $height == $this->owner->Height) { return $this; } if ($this->owner->Width > 0 && $this->owner->Height > 0 && $this->owner->CropWidth > 0 && $this->owner->CropHeight > 0) { return $gd->crop($this->owner->CropY, $this->owner->CropX, $this->owner->CropWidth, $this->owner->CropHeight)->resize($width, $height); } else { return $gd->croppedResize($width, $height); } }
public function __construct($mode = false, $sub_dir = false) { // Define some constants if (!defined('FM_DL_ERROR_EXPIRED')) { define('FM_DL_ERROR_EXPIRED', 1); } if (!defined('FM_DL_ERROR_MAXDL')) { define('FM_DL_ERROR_MAXDL', 2); } if (!defined('FM_DL_ERROR_NOFILE')) { define('FM_DL_ERROR_NOFILE', 3); } if (!defined('FM_DL_ERROR_NOPRODUCT')) { define('FM_DL_ERROR_NOPRODUCT', 4); } if (!defined('FM_DL_ERROR_NORECORD')) { define('FM_DL_ERROR_NORECORD', 5); } if (!defined('FM_DL_ERROR_PAYMENT')) { define('FM_DL_ERROR_PAYMENT', 6); } switch ($mode) { case self::FM_FILETYPE_DL: $this->_manage_root = CC_ROOT_DIR . '/files'; break; case self::FM_FILETYPE_IMG: default: $mode = 1; $this->_manage_root = CC_ROOT_DIR . '/images/source'; $this->_manage_cache = CC_ROOT_DIR . '/images/cache'; } $this->_mode = (int) $mode; $this->_manage_dir = str_replace(CC_ROOT_DIR . '/', '', $this->_manage_root); $this->_sub_dir = $sub_dir ? $this->formatPath($sub_dir) : null; //Auto-handler: Create Directory if (isset($_POST['fm']['create-dir']) && !empty($_POST['fm']['create-dir'])) { $create = $this->createDirectory($_POST['fm']['create-dir']); } // Auto-handler: image details & cropping if (isset($_POST['file_id']) && is_numeric($_POST['file_id'])) { if (($file = $GLOBALS['db']->select('CubeCart_filemanager', false, array('file_id' => (int) $_POST['file_id']))) !== false) { if (isset($_POST['details'])) { if (!$this->filename_is_illegal($_POST['details']['filename'])) { // Update details $new_location = $current_location = $this->_manage_root . '/' . urldecode($this->_sub_dir); $new_filename = $current_filename = $file[0]['filename']; $new_subdir = $this->_sub_dir; if ($file[0]['filename'] != $_POST['details']['filename']) { $new_filename = $this->formatName($_POST['details']['filename']); } if (isset($_POST['details']['move']) && !empty($_POST['details']['move'])) { $move_to = $this->_manage_root . '/' . $this->formatPath($_POST['details']['move']); if (is_dir($move_to)) { $new_location = $move_to; $new_subdir = $this->formatPath(str_replace($this->_manage_root, '', $new_location), false); } } // Does it need moving? if ($new_location != $current_location || $new_filename != $current_filename) { if (file_exists($current_location . $current_filename) && rename($current_location . $current_filename, $new_location . $new_filename)) { $this->_sub_dir = $new_subdir; $current_location = $new_location; $current_filename = $new_filename; // Database record $record['filename'] = $new_filename; $record['filepath'] = $this->formatPath($this->_sub_dir); $record['filepath'] = $this->_sub_dir == null ? 'NULL' : $this->formatPath($this->_sub_dir); } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_moved']); } } $record['description'] = strip_tags($_POST['details']['description']); $update = false; foreach ($record as $k => $v) { if (!isset($file[0][$k]) || $file[0][$k] != $v) { $update = true; } } if ($update) { if (!$GLOBALS['db']->update('CubeCart_filemanager', $record, array('file_id' => (int) $_POST['file_id']))) { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_update']); } } } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_file_update']); } } if (isset($_POST['resize']) && !empty($_POST['resize']['w']) && !empty($_POST['resize']['h'])) { $resize = $_POST['resize']; if (file_exists($this->_manage_root . '/' . $this->_sub_dir . $current_filename)) { // Use Hi-res image $source = $this->_manage_root . '/' . $this->_sub_dir . $current_filename; $size = getimagesize($source); $gd = new GD(dirname($source), false, 100); $gd->gdLoadFile($source); # TO DO: ROTATION $gd->gdCrop((int) $resize['x'], (int) $resize['y'], (int) $resize['w'], (int) $resize['h']); if ($gd->gdSave(basename($source))) { // Delete previously generated images preg_match('#(\\w+)(\\.\\w+)$#', $current_filename, $match); if (($files = glob($current_location . $match[1] . '*', GLOB_NOSORT)) !== false) { foreach ($files as $file) { if ($file != $source) { unlink($file); } } } $GLOBALS['gui']->setNotify($GLOBALS['language']->filemanager['notify_image_update']); } else { $GLOBALS['gui']->setError($GLOBALS['language']->filemanager['error_image_update']); } } } httpredir(currentPage(null, array('subdir' => $this->formatPath($this->_sub_dir, false)))); } } // Create a directory list $this->findDirectories($this->_manage_root); }
function generateFrontImage(GD $gd) { $gd->setQuality(90); return $gd->paddedResize(120, 160); }