Paste image from clipboard to upload

How about image optimization? I don’t know much about this, but I’m assuming that if you directly upload the bitmap content of the clipboard, the image will not be optimized.

Can a simple optimization process be included in the implementation, say, compressing the image to 80% quality JPG?

How can you be sure that everyone wants their images degraded like that? It’s far from “optimum” for everyone. This idea is plugin territory.

1 Like

Isn’t this the general idea/advice when publishing images to the web? For fast loading and browsing? The 80% quality JPEG is just an example. Perhaps there is a more optimal compression ratio.

The use case for this petition is for easily inserting screenshots into posts, and I think that screenshots need not be of high-quality.

If someone wants to publish high-quality images, say for feature images, then the upload function in Media Library can be used.

It is the other way around :smiley:
If someone wants their images in any way different than the original, say “optimised” or “smushed” or whatever, then they shall install a plugin that does that (there are plenty of them)

Having a different process in Media Upload vs Editor upload vs Editor paste would be a mess, because you would not have a “steady” or “always the same” approach to all image, thus, if you would need to add a plugin to (example) smush the images added in media upload, then that would also smush those inserted in the editor, and those would be already “optimised”… then you would get a mess of somewhat OK images and somewhat over-optimised images.

Also, someone might actually already optimise their images before uploading (I do that for example, using strict rules of size and dimensions of an image before it is uploaded).
That means, I need no add-on plugin doing that for me, as I already upload sensed images (and not a 7000px thing like some folks do :stuck_out_tongue:)


No, I offered green apples. Just talking about delivering them in an already existing box instead of fabricating a new box. It will reduce shipping costs (effort). And since the box has actually more apples in it, it makes sense to put 'em in the same box so it’s easier to keep track of apples related stuff.

And yep, this petition has nothing to do with compressing images. It’s about detecting and autouploading pasted images.

Compression solutions can be implemented and added to the media upload hooks. Since I will be using native media uploading function, they should work fine wherever the image is uploaded (media lib, paste functionality, …).

And yeah, as stated before, I don’t want to start a new plugin for this. I got this working on the ClassicEditor research plugin. So it will wait there until it’s okay for the community to merge it there.

I’m assuming that no image-optimizing plugin is installed, since whoever wants to upload a high-quality image will not install such a plugin.

As for me, I also already optimize my images before uploading. The only way “Editor pasting” will be useful to me (and save me time) is if it also optimize the images.

You can always install a compression plugin to benefit from image compression. That’s the good thing about modular design.

1 Like

Auto-compress after uploading? I’ll think about it :slight_smile:

That’s what compression plugins do.

  • Image gets uploaded
  • Image gets compressed
  • Original image gets replaced with compressed image

There isn’t much to think about here. Your point is very logic (you only focus on media editor so you want it there), but as stated, it’s independent functionality and it should have single handlers. If I add a compression system to the autopaste callback, then it will be code that can only be used by pasting the image into the editor, and not by using the media lib upload button. It will be code living in prison forever. Bad thing.

The ideal thing is to let another plugin handle that part by jumping into the upload process (wherever the upload happens) and doing the compression there.

That makes the whole story modular, so that only people who want to use that feature use it, and it’s not forced into everyone.

For me it’s okay to merge it to the ClassicEditor research plugin.
But if it’s not another option could be to merge it in the Enriched Editor plugin.
This means also to make it compatible with Tiny5. At the moment it is working in the editor part, but the configuration page seems to have some broken CSS.

1 Like

How exactly uploading pasted image from clipboard degrades image or is different from default optimization? CP already “crunches” images by default, so uploaded images are not original quality.

If @alvarofranz uses built in hooks to upload images, they do get basic optimization that is built in. CP optimizes JPG images by default using GD. I believe default quality is around 80% and can be changed using jpeg_quality.

1 Like

I was going out so I didn’t have time to explain.

Of course I know what compression plugins do, but I did not assume that the uploaded images thru Editor pasting will also be automatically optimized by an installed compression plugin just after or while being uploaded. But if you’re implying that that will be the case, then I have no problem.

Well, the title of the petition is “Paste image from clipboard to upload” and so it’s natural for me to assume that what you’re proposing will be limited to pasting images only.

But yeah, I know that your petition is only merged to this one.

I didn’t know this. Thanks for the info.

Well, that settles it then. If @alvarofranz will use built in hooks so that the uploaded images get basic optimization, then this petition gets my vote.

1 Like

I was going to ask how… and found this Does WordPress automatically compress images? Image resizing tips. - WP Website Tools

Outrageous if you ask me. As if somehow this would improve anything in respect to speed.

Anyway, learned a new favorite filter to use from now on lol


With regard to image, jpg, compression. If you upload a correctly sized picture, (height and width) at a compression of 70% you would generally not see any degregation (there will always be rare execptions).

The only real reason to save at 100% is if you are going to be doing further editing as compression errors are cumulative, and if you are editing images you are unlikely to be using jpg anyway. I would do edits in png and export at the apropriate format, size and quality for the application

If you are using for example a 1920 x 560 header image with overlay text the visitor will be reading the text not admiring the image. So a 100% quality image uploaded, compressed by wordpress, could still be 1meg or more, optimally compressed this might only be 70k this makes a huge difference in the load time for the page with no disernable difference to the site visitor…
CP creates several ,4, copies of an uploaded images, themes and page builders can add several more.
So uploading a 2Mb image could use up 20Mb of storage on your server.
Many servers will compress images as there serve them, as will most caching and optimising plugins.

So if you upload an optimally sized and compressed image, using photoshop, fireworks,gimp, etc. at say 75% (or less) this is going to be least affected (abused) by CP, your server, optimising plugins etc. and be fast to load.
Uploading an image of the quality and size that you could print out for a wall could actually end up looking bad when displayed on a mobile or desktop monitor and be very slow to load.

I was not aware of that. Thanks! Good thing I always stick to SVGs!

Photos should be stored as JPEG since that’s what that format is specifically for: compressing real-life images in a way that does not make them look significantly worse to the human eye.

Screenshots and any other image that is supposed to contain large stretches of exactly the same color with sharp edges (for example, computerized drawings) should never be compressed with JPEG. They will look terrible and these should be uploaded as .png instead. They will compress well and this is what the PNG image format is for.

What if you make a meme that is based on a photo but has sharp-edged text? Should this be stored as JPEG or PNG?

I don’t see how a computer can make that decision.

Clipboard images can be in different formats. It is not always obvious how to do so, but I can choose to copy an image to the clipboard in JPG or PNG format. @alvarofranz under your current code, is the clipboard’s image format (MIME type) respected when pasting and uploading?

1 Like

Yes, sir. Getting 'em as blob. Sending 'em as files via Ajax. So, MIME Type is respected.

1 Like

Ok, great :slight_smile:

Why do you think this is a waste of time?

Anyway the other option would be to send this as a PR against the current version of ClassicPress.

1 Like

More than a waste of time it feels like a waste of energy, cuz I have to go read documentation for an old version of TinyMCE, to check what needs to be done differently. This section in the Tiny v4 docs talks about editor events.

In this case it’s just a minor difference but it drains my energy. I just want to make stuff work on modern technology. If there is a v5 I don’t want to have to deal with v4. The ClassicEditor Research plugin seems like a good place to add this because I won’t have to make adjustments for v4. It is the place where the next CP editor is being cooked, so yeah, it’s a good place to throw that feature in.

Thanks for your attention. I will keep working on this since I am using it (CP and the research editor), and I will be happy to PR that if it’s okay. And not PR if it’s not okay :slight_smile: