Search code examples
phpsummernote

Summernote - Adding images with file-size limit


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?


Solution

  • 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.