Source of file EnhancedImage.php
Size: 4,649 Bytes - Last Modified: 2021-12-24T05:20:00+00:00
/var/www/docs.ssmods.com/process/src/src/Model/EnhancedImage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 | <?php namespace Jellygnite\Enhance\Model; use SilverStripe\Assets\File; use SilverStripe\Assets\Storage\DBFile; /* * SVG Support * * Instructions * in your Data Object private static $has_one = array( 'Image' => File::class, // use file class but limit file categories to support SVG ); public function getCMSFields() { $this->beforeUpdateCMSFields(function (FieldList $fields) { $image = $fields->dataFieldByName('Image') ->setDescription(_t(__CLASS__.'.ImageDescription', 'Optional. Display an image.')) ->setAllowedFileCategories('image/supported','image/unsupported'); $fields->addFieldToTab( 'Root.Images', $image ); } } * If you are allowing SVG uploads, to avoid potential for script execution in malicious SVG files, it is safer to use in your template. <img src="$Image.ScaleMaxWidth(640).URL" alt="$Image.Title.ATT"> * Best to limit uploads to admin only, i.e. don't enable SVG upload in front end. * */ class EnhancedImage extends File { public function forTemplate() { if($this->owner->IsSVG()) { $template = 'DBFile_image'; return (string)$this->renderWith($template); } return parent::forTemplate(); } public function getFileType(){ if($this->getExtension()=='svg') return "SVG image - good for line drawings"; return parent::getFileType(); } public function Pad($width, $height, $backgroundColor = 'FFFFFF', $transparencyPercent = 0) { if($this->owner->IsUnsupported()) { return $this; } return parent::Pad($width, $height, $backgroundColor, $transparencyPercent); } public function Resampled() { if($this->owner->IsUnsupported()) { return $this; } return parent::Resampled(); } public function ResizedImage($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::ResizedImage($width, $height); } public function Fit($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::Fit($width, $height); } public function FitMax($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::FitMax($width, $height); } public function ScaleWidth($width) { if($this->owner->IsUnsupported()) { return $this; } return parent::ScaleWidth($width); } public function ScaleMaxWidth($width) { if($this->owner->IsUnsupported()) { return $this; } return parent::ScaleMaxWidth($width); } public function ScaleHeight($height) { if($this->owner->IsUnsupported()) { return $this; } return parent::ScaleHeight($height); } public function ScaleMaxHeight($height) { if($this->owner->IsUnsupported()) { return $this; } return parent::ScaleMaxHeight($height); } public function CropWidth($width) { if($this->owner->IsUnsupported()) { return $this; } return parent::CropWidth($width); } public function CropHeight($height) { if($this->owner->IsUnsupported()) { return $this; } return parent::CropHeight($height); } public function FillMax($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::FillMax($width, $height); } public function Fill($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::Fill($width, $height); } public function Quality($quality) { if($this->owner->IsUnsupported()) { return $this; } return parent::Quality($quality); } public function CMSThumbnail() { if($this->owner->IsUnsupported()) { return $this; } return parent::CMSThumbnail(); } public function StripThumbnail() { if($this->owner->IsUnsupported()) { return $this; } return parent::StripThumbnail(); } public function PreviewThumbnail() { if($this->owner->IsUnsupported()) { return $this; } return parent::PreviewThumbnail(); } public function Thumbnail($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::Thumbnail($width, $height); } public function ThumbnailIcon($width, $height) { if($this->owner->IsUnsupported()) { return $this; } return parent::ThumbnailIcon($width, $height); } } |