Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

resampled images replace original ones (without resizing)

Go to End

6 Posts   8063 Views


126 Posts

29 November 2007 at 9:46pm

Edited: 29/11/2007 10:13pm

Hi again,

I am wondering why Silverstripe uses a resampled image instead of the original one, even though I did not edit or resize the image?

Silverstripe creates a _resampled folder in a subfolder of "assets" when I click on "insert image" in the TinyMCE rich text editor and chose a subfolder. In the TinyMCE input field it displays the correct image, but in the frontend on the actual public website it displays the resampled image (e.g. /assets/_resampled/ResizedImage200300-myimage.gif). I noticed a number of disadvantages for GIF images:

- transparent areas become black
- animated GIFs are static (first frame only)
- colours may appear wrong/dithered (probably the resampling may create a different colour index than the original one so that homogenous areas in one colour may be resampled with two colours, or two colours that look nearly identical may be resampled as colours with a higher contrast; this creates a pixelated effect)
- file sizes may be bigger (also for JPEGs)

I did not test PNG images yet but I guess there will be the same issues.

While the problems listed above may be hard to fix I do not see the need to use a resampled image if the image is not resized.

I will look into this further, but if anyone knows a way to force Silverstripe to use the original image I would be keen to know how.



121 Posts

29 November 2007 at 11:38pm

The only way I found of stopping the resampling was to remove the width/height attributes from the image. It would be nice to have a cleaner way of telling the CMS that you want to place an image without resampling though.

I've not tried this in 2.2.0, so it might have changed - the image placement stuff has been modified quite a bit in the latest release.


126 Posts

30 November 2007 at 9:53am


thank you! When I remove the width/height attributes the original image is displayed. I successfully tested this in Silverstripe 2.2.0rc3.

It would probably be a good idea if Silverstripe would use the original image by default if the image is not resized or if there was a checkbox like: "do not resample".

At the moment one small disadvantage of removing the width and height attributes in the CMS is that the <img> tag on the published site does not have the width and height attributes either.



126 Posts

5 December 2007 at 12:18pm

Hi again,

I found a way to make Silverstripe use the original image if the image was not resized. In /sapphire/core/model/Image.php add the lines in red to the cacheFilename() method in the Image() class:

function cacheFilename($format, $arg1 = null, $arg2 = null) {
	$folder = $this->ParentID ? $this->Parent()->Filename : "assets/";
	if ($this->getDimensions() == $arg1.'x'.$arg2) {
		return $folder . $this->Name;
	$format = $format.$arg1.$arg2;
	return $folder . "_resampled/$format-" . $this->Name;

This will automatically use the original image file if the image was not resized; not a resampled image. See my post above for a list of disadvantages that may occur through resampling. As opposed to the alternative method pointed out above by jam13 using this way the <img> tag in the published site still contains the width and height attribute, and it saves you the task to delete the width and height attributes for every image you don't want to have resampled.

The code above reads the image dimensions from the original image file - and luckily this only seems to happen when you click on the save/publish button in the CMS, not when you visit the published frontend site, so there should be no performance loss on the public site.



Community Member, 52 Posts

12 September 2008 at 8:47pm

Hi Anatol:
Thank you very much. You save my day.


Community Member, 7 Posts

30 September 2008 at 9:50am


Thanks!!! Great contribution.