Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » resampled images replace original ones (without resizing)

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

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

Page: 1
Go to End
Author Topic: 6397 Views
  • Anatol
    Avatar
    126 Posts

    resampled images replace original ones (without resizing) Link to this post

    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.

    Cheers!
    Anatol

  • jam13
    Avatar
    121 Posts

    Re: resampled images replace original ones (without resizing) Link to this post

    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.

  • Anatol
    Avatar
    126 Posts

    Re: resampled images replace original ones (without resizing) Link to this post

    Hi,

    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.

    Cheers!
    Anatol

  • Anatol
    Avatar
    126 Posts

    Re: resampled images replace original ones (without resizing) Link to this post

    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.

    Cheers!
    Anatol

  • nomen
    Avatar
    Community Member
    52 Posts

    Re: resampled images replace original ones (without resizing) Link to this post

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

  • Krato
    Avatar
    Community Member
    7 Posts

    Re: resampled images replace original ones (without resizing) Link to this post

    Anatol,

    Thanks!!! Great contribution.
    Regards

    6397 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.