I’ve been googling everywhere to find a way to prevent any images bigger than 500kb but haven’t found a single solution. The reason why I’m trying to limit the file size of images is for mobile users using limited data plans.
I ended up believing that it’s impossible because summernote saves images as text something like this…..
<img style="width: 640px;" src="data:image/jpeg;base64,/9j/4Qv6RXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAeAAAAcgEyAAIAAAAUAAAAkIdp...............>
and generate back as an image when needed.
Do I still need to limit the file size even if I store them as text in DB?
If I have to, is there an api for this?
If i understand correctly you use this https://github.com/summernote/summernote/blob/develop/src/js/settings.js please check the maximumFileSize: ‘Maximum file size’, parameter in the image option. In there you can set the limit you want.
Answer:
You can limit the picture size in summernote plugin by adding these options:
$('.summernote').summernote({
// your options... and
maximumImageFileSize: 500*1024, // 500 KB
callbacks:{
onImageUploadError: function(msg){
console.log(msg + ' (1 MB)');
}
}
});
Answer:
Check this link: https://github.com/summernote/summernote-rails/issues/22
$(‘.summernote’).summernote({
maximumImageFileSize: 1048576
});