[英]How to watermark wordpress images from wp-content/uploads folder with htaccess and php?
I have a Wordpress website, due to some limits i need to have originals of the photo at the serverside, but watermarked ones on a frontend and with direct opening of the photos. 我有一个Wordpress网站,由于某些限制,我需要在服务器端拥有照片的原件,但要在前端添加水印并直接打开照片。 I'm using Frontend content creation plugin and (as i understand) not all the plugins will fork with custom file input fields (wp_handle_upload used).
我使用的是Frontend内容创建插件,并且(据我了解),并非所有插件都将带有自定义文件输入字段(使用了wp_handle_upload)。 I've found good solution: php file + htaccess setting with RewriteRule.
我找到了很好的解决方案:php文件+带有RewriteRule的htaccess设置。 The problem is that it isn't work for me for some reason.
问题是由于某种原因它对我不起作用。
The solution is: http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/ 解决方案是: http : //dolcepixel.com/how-to-watermark-all-your-uploaded-images/
When i opening file with: 当我打开文件时:
/watermark.php?p=br&q=90&src=wp-content/uploads/link/to/file.jpg /watermark.php?p=br&q=90&src=wp-content/uploads/link/to/file.jpg
everything is good, watermark is on the image, but when this image loads on the page or direct link in the browser - nothing happens. 一切都很好,图像上有水印,但是当该图像加载到页面或浏览器中的直接链接上时,什么也没有发生。 It loads original image without watermaks.
它将加载原始图像,而不会出现水渍。
There is two main settings: htaccess rule 有两个主要设置:htaccess规则
RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1
And full block of mod_rewrite section: 以及mod_rewrite部分的完整块:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1
</IfModule>
the php file is bigger and it's works as i see, the problem is in something else, but you can find the .php at the link on top of the post. php文件更大,并且如我所见,它的工作原理是其他问题,但是您可以在文章顶部的链接中找到.php。
Whats the problem with me, or Apache, .htaccess or with Wordpress? 我或Apache,.htaccess或Wordpress有什么问题? If there is a way to deny any access to /uploads/ with possibility to open images throught php proxy – it is a solution also, but when i'm trying to use /wp-content/uploads/.htaccess with "deny from all" it wont work and the direct file is opens without any problems with browser.
如果有一种方法可以拒绝对/ uploads /的任何访问,并有可能通过php代理打开图像–这也是一种解决方案,但是当我尝试将/wp-content/uploads/.htaccess与“拒绝所有“它将无法正常工作,直接文件打开后浏览器不会出现任何问题。
Recently i have same problem and in my case answer vas very easy - Cashing. 最近我有同样的问题,在我的情况下,回答很容易-兑现。 So try to clear cache when you make some changes, even in .htaccess, or use another browser.
因此,当您进行了一些更改(即使在.htaccess中)或尝试使用其他浏览器时,请尝试清除缓存。 Hope it helps
希望能帮助到你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.