简体   繁体   中英

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. 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). I've found good solution: php file + htaccess setting with RewriteRule. 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/

When i opening file with:

/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

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:

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

Whats the problem with me, or Apache, .htaccess or with 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.

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. Hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM