»WordPress»Realize compatibility between image watermark and image pop-up window by skillfully using CDN image processing
A special gesture is used to unlock CDN cloud storage, that is, Qiniu, Youpai. OSS has more ways to play with pictures, enabling the article pictures to have the function of thumbnail+watermark+image pop-up.
preface
I don't know when someone asked me a question: since thumbnails can be directly used by Qiniu or another photo, can the image watermark of articles also directly use the CDN watermark function?When I saw this problem, I started to experiment, but I gave up for a long time, mainly because the picture style of the article will affect Git's picture pop-up window. Because Git's breakthrough pop-up window uses the fancybox scheme, I don't know whether others' is also incompatible. Later, I found that Baidu also has similar problems, so I gave up,But not long ago, I came across a picture style, but it was solved in a very strange way. Let's talk about it today.
terms of settlement
First of all, the first picture of this article is to open the watermark+thumbnail [I temporarily removed the watermark from this website, so I can't see it, and the watermark in the lower right corner comes with the screenshot tool]. Although my watermark is removed at present, it will not affect my viewing. My image link suffix is added!water.jpgIf you only look at the displayed image, its width should be only 750px, but the size of the image after Di Ali is 1920px. That is to say, the image loaded on the web page before is 750px, which is a thumbnail of the original image. If you look at the size of the image, it will be even more different. I think you must understand what I mean by naming the image style as【water.jpg】Of course, you can also be others, such asgooglo.png, such ashappy.gifIn short, let the plugin in the image pop-up window think that this is the original image.
Actual measurement: Qiniu, Youpai, OSS supports this image style naming method
Watermark code
In fact, this article is mainly about ideas. It doesn't matter what the watermark code is. Here you can paste it. This is the watermark code used by Cloudfall. All pictures here will be watermarked
function git_cdn_water($content) {global $post;$pattern ="/<img(.*?)src=('|\")(.*?).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>/i";$replacement = '<img$1src=$2$3.$4!Water. jpg $5 $6>';//Change to your own image style name$content = preg_replace($pattern, $replacement, $content);return $content;}add_filter('the_content', 'git_cdn_water');
Optional watermark
The above code is that all the pictures are watermarked, but sometimes the beautiful pictures we upload are watermarked and don't look very good. Here is an optional version, but if the image watermark is used, the image pop-up window must be kept. If the watermark is not used, the pop-up window is not needed