问题
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