/** * Calls the original writeTo function and then after that completes optimises the image * @param string $filename */ public function writeTo($filename) { parent::writeTo($filename); if ($this->optimiserService instanceof ImageOptimiserInterface) { $this->optimiserService->optimiseImage($filename); } }
/** * Merge two Images together */ public function merge(GDBackend $image) { imagealphablending($this->owner->getImageResource(), false); imagesavealpha($this->owner->getImageResource(), true); imagealphablending($image->getImageResource(), false); imagesavealpha($image->getImageResource(), true); $srcX = 0; $srcY = 0; $srcW = $image->getWidth(); $srcH = $image->getHeight(); $dstX = round(($this->owner->getWidth() - $srcW) / 2); $dstY = round(($this->owner->getHeight() - $srcH) / 2); $dstW = $image->getWidth(); $dstH = $image->getHeight(); imagecopyresampled($this->owner->getImageResource(), $image->getImageResource(), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH); $output = clone $this->owner; $output->setImageResource($this->owner->getImageResource()); return $output; }
/** * Calls the original writeTo function and then optimizes the image * @param String $filename */ public function writeTo($filename) { parent::writeTo($filename); $siteConfig = SiteConfig::current_site_config(); if (!$siteConfig->DisableKraken) { $krakenService = new KrakenService(); $data = $krakenService->optimizeImage($filename); //check if optimization was success if ($data['success'] && $data['saved_bytes'] >= 0) { //attempt to download the kraked file $krakedFile = $krakenService->getOptimizedImage($data['kraked_url']); //update the file if ($krakedFile) { file_put_contents($filename, $krakedFile); } } } }
/** * @deprecated 3.2 Use the "GDBackend.default_quality" config setting instead */ public static function set_default_quality($quality) { Deprecation::notice('3.2', 'Use the "GDBackend.default_quality" config setting instead'); GDBackend::set_default_quality($quality); }
* @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');
/** * Test that GD::failedResample() returns true for the current image * manipulation only if it previously failed * @return void */ public function testFailedResample() { $fullPath = realpath(dirname(__FILE__) . '/gdtest/nonimagedata.jpg'); $fullPath2 = realpath(dirname(__FILE__) . '/gdtest/test_gif.gif'); // Load invalid file $gd = new GDBackend(); $gd->loadFrom($fullPath); // Cache should refre to this file $this->assertTrue($gd->failedResample($fullPath, filemtime($fullPath))); $this->assertFalse($gd->failedResample($fullPath2, filemtime($fullPath2))); }
/** * @usage can be used in a template like this $Image.LargeImage.Link * @return GDBackend **/ function generateLargeImage(GDBackend $gd) { $gd->setQuality(90); return $gd->resizeByWidth($this->LargeWidth()); }
/** * convert to jpeg */ public function toJpeg($backgroundColor, $type) { $image = $this->owner->getImageResource(); switch ($type) { case IMAGETYPE_GIF: case IMAGETYPE_PNG: $newGD = imagecreatetruecolor($this->owner->getWidth(), $this->owner->getHeight()); $bg = GDBackend::color_web2gd($newGD, $backgroundColor); imagefill($newGD, 0, 0, $bg); imagealphablending($newGD, TRUE); imagecopy($newGD, $image, 0, 0, 0, 0, $this->owner->getWidth(), $this->owner->getHeight()); break; case IMAGETYPE_JPEG: $newGD = $image; break; } $output = clone $this->owner; $output->setImageResource($newGD); return $output; }
/** * Test that GD::failedResample() returns true for the current image * manipulation only if it previously failed * @return void */ public function testFailedResample() { $fullPath = realpath(dirname(__FILE__) . '/gdtest/test_jpg.jpg'); try { $gdFailure = new GDBackend_Failure($fullPath, array('ScaleWidth-failed', 123)); $this->fail('GDBackend_Failure should throw an exception when setting image resource'); } catch (GDBackend_Failure_Exception $e) { $gd = new GDBackend($fullPath, array('ScaleWidth', 123)); $this->assertTrue($gd->failedResample($fullPath, 'ScaleWidth-failed|123')); $this->assertFalse($gd->failedResample($fullPath, 'ScaleWidth-not-failed|123')); } }
public function writeTo($filename) { parent::writeTo($filename); $this->addWatermarkTo($filename); }