WordPress.org

Forums

Imaguard
[resolved] Options to set font size, text position and reduce opacity of overlay (10 posts)

  1. RogueSkolar
    Member
    Posted 2 years ago #

    Hi,

    Great plugin! Thanks very much for developing this.

    Are there any chances of adding options to set the font size, the position of watermark text and opacity of the overlay in the plugin's options panel?

    At the moment I'm having to hack the core to achieve these outcomes. It would be much cleaner if there were options to do this directly within the plugin's config panel.

    Regards.

    http://wordpress.org/extend/plugins/imaguard/

  2. imaguard
    Member
    Plugin Author

    Posted 2 years ago #

    Hi!

    Yes, we are working on this bit for the next version + the option to set text color. The current version was hurried through production as a lot of people were requesting the plugin after Google updated their image Search function.

    If you like the plugin we would greatly appreciate if you have time to post a star rating on http://wordpress.org/support/plugin/imaguard and also add a "working" vote for your WP version.

    I presume you are successfully "hacking" the Imaguard plugin to work the way you need it pending the next version. But if you get stuck or have any questions, just let us know.

  3. RogueSkolar
    Member
    Posted 2 years ago #

    Awesome,

    Thanks for the response. More than happy to rate it.

    The current version was hurried through production as a lot of people were requesting the plugin after Google updated their image Search function.

    I can imagine!

    Yeah I've been hacking the core to try and get the functionality I need pending the next release.

    I might be pushing it here, but what are the chances of redirecting the image to the actual post or page the image originates from? If possible instead of using the dynamically generated show-image page, I'd just like to redirect to the origin page for the obvious reason that these posts/pages are monetized and convert well.

    I'd be really grateful if you consider making this an option in your next release. If you could give me a couple of pointers as to how I can go about this pending your next release, I'd doubly as grateful.

    Regards.

  4. imaguard
    Member
    Plugin Author

    Posted 2 years ago #

    Redirecting to the post where the image was used creates some program logic challenges since an image can be used on many posts. But if you don't mind redirecting to the first post where it was used, you can hack Imaguard with something like this, I guess. Just replace the whole ir_createpage() function in imaguard/index.php with two new functions:

    function ir_getpostidbyurl($url) {
    	global $wpdb;
    	$query = "SELECT ID FROM {$wpdb->posts} WHERE post_content like '%".$url."%' LIMIT 1";
    	$thisid = $wpdb->get_var($query);
    	return $thisid;
    }
    
    function ir_createpage()
    {
    	$post = new stdClass;
    
    	$ir_location = "http://yoursite.com/index.php?p=".ir_getpostidbyurl($_GET['img']);
    	Header( "HTTP/1.1 302 Moved Temporarily" );
    	Header( "Location: $ir_location" );
    	exit;
    }

    (replace the yoursite.com bit of course).

    I haven't tested it, but it should work (let me know either way, if you try it out).

    However, this is pretty dirty. The query may slow down large sites and it does a 2nd redirect.

    We will try to implement something in an upcoming version. Maybe not the v 1.2.2 which we are planning for tomorrow, but pretty soon.

    Hope this helped a bit.

  5. RogueSkolar
    Member
    Posted 2 years ago #

    Many many thanks. You are a gentleman/woman and a scholar
    :-]

    But if you don't mind redirecting to the first post where it was used

    Actually this is perfectly fine and precisely what I've been trying to do because most of my images are "tied" to a unique post or page. I use the images in other places (posts) but only as an aside in post snippets. So in nearly all cases the place where they are most relevant contextually is the post they are tied to, or on which they first appear.

    Happy to report I've tried this out and so far it seems to be performing well without a noticeable performance hit. I'll need to monitor this over the coming weeks but so far it looks good.

    One more question if I may, I'm currently using a less aggresive approach. Just for testing purposes, I've hotlinked an image from one of my sites (remote) on a sandbox site I've got running locally. The hotlinked image on the sanbox site is not showing (.ie it is blocked). Should this be the case? My thinking is that the image on the sandbox site should still show no?

    Really great news to see you will consider the rolling in the origin post/page redirect in a future release. Very promising. I'll be spreading the word about your plugin as far and wide as I can.

    Looking forward to the next release.

    Regards.

  6. imaguard
    Member
    Plugin Author

    Posted 2 years ago #

    Thank you for the kind words! Glad the hack works - hopefully we will come up with something less crude for a later version.

    When using the non-aggressive redirect functionality in Imaguard, hotlinking from non white listed sites won't work. The reason is that the image actually renders a html page, not an image file. Thus it will show blank if hotlinked as an image.

    Your image should still work in Google Image Search, though, since Googlebot-images stores a thumbnail on their server when crawling. The google image bot will normally use local referrers when crawling images, so it will see your images when crawling your site. You should still add all googlebot versions to your whitelist, though. The thumnail in the search will work normally - and the google image preview (the larger preview that was implemented recently) will show blurred. This is because Google uses javascript to first enlarge the thumbnail and then replaces it with the actual hotlinked image when that has loaded (you can see this if you try to click on some thumbnails not cached in your browser - it will be blurred for a short while and them become clear). Since the hotlinked image never loads, it will stay blurred, which is normally good as it encourages users to either click on "see original" or the actual picture. The latter leads to your blog post and the former hopefully redirects to the same.

  7. RogueSkolar
    Member
    Posted 2 years ago #

    Just to clarify the above on my sandbox site I've got two [hot]links to the remote image. The implementation is as follows:

    <!-- hotlinked image -->
    <figure>
       <img src="http://remotesite.com/wp-content/uploads/path-to-some-image.jpg" alt="">
       <figcaption>Some image caption</figcaption>
    </figure>
    
    <!-- direct hyperlink to image -->
    <a href="http://remotesite.com/wp-content/uploads/path-to-some-image.jpg">Original Image</a>

    The redirect works like a charm with respect to the hyperlink. The image however does not show. What would be gravy is to have non aggresive watermark generated dynamically over the hotlinked image whilst also redirecting to origin page when the image is accessed via the hyperlink.

    Kind regards.

  8. RogueSkolar
    Member
    Posted 2 years ago #

    I spoke too soon.

    Your image should still work in Google Image Search, though, since Googlebot-images stores a thumbnail on their server when crawling. The google image bot will normally use local referrers when crawling images, so it will see your images when crawling your site.

    Brilliant. This was my main concern.

    Since the hotlinked image never loads, it will stay blurred, which is normally good as it encourages users to either click on "see original" or the actual picture.

    Yes precisely. Genius. This is exactly what I'm going for.

    I'm much obliged for your direction.

    Big props guy.

  9. EcoCatLady
    Member
    Posted 2 years ago #

    Hi there,

    I haven't actually installed this plugin - I was hoping you'd figured out how to redirect to an image if the hotlink was embedded in a page, vs. to a page if the hotlinked image was opened in a separate browser window/tab. From what I'm reading here looks like it's an either/or solution at this point - which is sort of where I'm stuck myself.

    If you do figure out how to get it to redirect to an image vs. page in those different circumstances, I'll be installing this plugin pronto!

    BTW - just thought I'd share this bit of code. This was my original code redirecting to the actual post where the image was first uploaded. Can't take credit for it all as various chunks came from different forums, but it's nice because if the hotlink points to a wordpress generated thumbnail of the image rather than the original, it still takes you to the original post. This, of course, only works if you uploaded the image as a child to a post - if you uploaded it directly to the library then the image won't have a parentID and it won't work.

    This worked like a charm, but I wouldn't recommend using it on a big site or a site with many hotlinks coming in. With my site it slowed the server down to a crawl. So... I'm currently working on a less elegant solution that won't require loading wordpress for every hotlink request that comes in. Anyhow, if any part of this is helpful to you, please feel free to use it.

    <?php
    
    define( 'WP_USE_THEMES', false );
    require('wp-blog-header.php');
    
    function pn_get_attachment_id_from_url( $attachment_url = '' ) {
    
    	global $wpdb;
    	$attachment_id = false;
    
    	// If there is no url, return.
    	if ( '' == $attachment_url )
    		return;
    
    	// Get the upload directory paths
    	$upload_dir_paths = wp_upload_dir();
    
    	// Make sure the upload path base directory exists in the attachment URL, to verify that we're working with a media library image
    	if ( false !== strpos( $attachment_url, $upload_dir_paths['baseurl'] ) ) {
    
    		// If this is the URL of an auto-generated thumbnail, get the URL of the original image
    		$attachment_url = preg_replace( '/-\d+x\d+(?=\.(jpg|jpeg|png|gif)$)/i', '', $attachment_url );
    
    		// Remove the upload path base directory from the attachment URL
    		$attachment_url = str_replace( $upload_dir_paths['baseurl'] . '/', '', $attachment_url );
    
    		// Finally, run a custom database query to get the attachment ID from the modified attachment URL
    		$attachment_id = $wpdb->get_var( $wpdb->prepare( "SELECT wposts.ID FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = '_wp_attached_file' AND wpostmeta.meta_value = '%s' AND wposts.post_type = 'attachment'", $attachment_url ) );
    
    	}
    
    	return $attachment_id;
    }
    
    // set the image url
    $inurl=$_GET['p'];
    $attachment_url= "http://" . $_SERVER['HTTP_HOST'] ."/".$inurl;
    
    // store the image ID in a var
    $image_id = pn_get_attachment_id_from_url($attachment_url);
    
    // get post where image appears
    $parent = get_post_field( 'post_parent', $image_id);
    $link = get_permalink($parent);
    
    // add header
    header( "Location:$link" ) ;
    ?>
  10. imaguard
    Member
    Plugin Author

    Posted 2 years ago #

    Thank you for your post. We are planning a stand alone plugin that will skip the whole redirect system and generate the actual image file on the fly (so instead of show-image.php?img=img.jpg you simply load img.jpg directly and a handler will generate the correct version based on the referrer and user agent. Because of the rather complicated file structure WP uses for uploads, such a plugin will require a rather intrusive use of htaccess files in a number of subfolders. Therefore we are not planning to make it part of the standard Imaguard which is a "gentler" plugin :)

    In any case the problem will always remain; how do you distinguish between hotlinking and direct access? Neither user agent nor referrer can be trusted to give such information. The only way we have come up with is encoded timestamping of images (image.jpg?timestamp=AGHFHS). Anyone accessing an image with an out of date timestamp is probably accessing it through a hotlink outside your control.

    Anyway, thanks for sharing the code!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Imaguard
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags