silverstripe / tinymce - stop automatic resize

人盡茶涼 提交于 2019-12-11 04:46:27

问题


Using Silverstripe CMS (v3.4) when I upload an image using the tinymce editor it automatically sets the width/height on the image. This causes problems such as breaking animated gifs so they don't play and also reduces the quality of static images.

How do I turn this feature off completely so that no resizing is done on upload?


回答1:


You can modify the insert width of the images instead of them being resized to 600px wide.

mysite/_config.yml

HtmlEditorField:
  insert_width:
    1200

You can also override the width / height attributes on the image tag with css.

.typography img {
  width: 100%;
  max-width: 100%;
  height: auto;
}

Its not great but its the only work around which I know.

As for animated gifs, these are always going to break if they are resized with php.




回答2:


HTMLEditorField updates img tags in it's saveInto function. Inside the saveInto function is a processImage extension hook that allows us to manipulate images inserted using TinyMCE.

First we create a CustomHTMLEditorField extension with a processImage function. If the image is a gif we set the img src back to the original image path.

SilverStripe 3

class CustomHTMLEditorField extends Extension
{
    public function processImage($image, $img)
    {
        if ($image->getExtension() == 'gif') {
            $img->setAttribute('src', $image->getRelativePath());
        }
    }
}

Next we add the extension to HtmlEditorField in our config.yml file:

HtmlEditorField:
  extensions:
    - CustomHTMLEditorField



回答3:


Don't add images in TinyMCE… it doesn't properly support hi-dpi images and it's really hard to control the resulting layout.

Better use something like a content-block module or just use separate image-upload fields. You could also use something like the shortcodable module to insert media such as images via custom shortcodes.



来源:https://stackoverflow.com/questions/45233691/silverstripe-tinymce-stop-automatic-resize

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!