Here's the deal: My plugin automatically watermarks images from the WP gallery on the fly using the GD library wherever these images appear. So, I have a physical copy (in wp-uploads) of these attachments, and also a watermarked, dynamic copy of the image which I replace the image source on the page using Simple HTML DOM.
So now, I have an image on my page that points to a URL like this:
http://localhost/wp-content/plugins/pluginname/image.php?original=http%3A%2F%2Flocalhost%2Fwp-content%2Fuploads%2F2012%2F09%2FPenguins-300x225.jpg&username=&wmtext=localhost&wmsize=14&wmcolor=%23000000&wmpos=top-center&pin_hoveron=1&pin_hoverimg=http%3A%2F%2Flocalhost%2Fwp-content%2Fplugins%2Fpluginname%2Fadd-to-etc.png&followimg=&pin_on=1&follow_on=1
What I want to do is make the image source APPEAR like it is the original version, but display the dynamic image instead. I've attempted to mess around with rewrite rules, but it never seems to do anything, no matter what I try. The rules get added to .htaccess, but nothing changes. Here's what I was messing around with:
add_action('generate_rewrite_rules', array( $this, 'addRewrites' ) );
public function addRewrites( $content ) {
global $wp_rewrite;
$new_rules = array(
'img/(.*)' => plugins_url( 'image.php', __FILE__ ) . '?etc=$1',
);
$wp_rewrite->non_wp_rules += $new_rules;
}
Now if I visit an image URL or a page with an image, NOTHING happens. =/ I'm a newbie when it comes to rewrite rules, so this is a bit beyond me.