📜 ⬆️ ⬇️

Resize images from the web or the fight against harmful users ...

Need advice on implementation.

Given: Drupal, Bueditor , material (which is added by registered users).

Each user wants to add a picture to the post, so that his material would look better, but there is no possibility of uploading images to the site; Accordingly, the user simply throws the url, which is written with the IMG tag. All anything, but the user can find a file with a resolution of 25002500px and it is easy to insert it, thus, in the literal sense of the word, tear the site apart.


Task: do not allow the user to break the site.
')
Decision:
The design of the placement of images in the material is as follows:

«div class="content"» «img src="LINK"» «/div»

in styles just spelled:

div.content img {max-width:500px;}

Considering that 6 IE and his ancestors will not understand this in a separate css,
which is loaded exclusively for IE inserted:

div.content img { width: expression(this.offsetWidth < 500 ? "auto" : 500); }

As a result, if the user has inserted an image larger than 500px in width, it will be resized by the browser, if less than 500, it is displayed as it is ...
I did the right thing or is there a more convenient and competent solution to this problem?

Thank…

APDate
I’ll repeat uploading to the server and post processing the image on it doesn’t fit;

By the way, at Habré, there is no protection against a fool with the desire to insert an image of 2500x2500px, too, if only the self-regulation mechanism.

Yes, the above solution has a bunch of minuses like this: the image is resizable by the browser crookedly, the user loads the entire file, even though it is visible across the width of 500px and so on.

But ... all these disadvantages are also present if this code is not provided + the site break is added to them.

Something like that…

Source: https://habr.com/ru/post/27426/


All Articles