syamilmj / Aqua-Resizer

Resize WordPress images on the fly
502 stars 208 forks source link

Retina support #14

Closed mintplugins closed 11 years ago

mintplugins commented 11 years ago

This is something we have used for a few months now on http://mintthemes.com and it works really well. It detects whether the person is on a retina device or not and then sets a javascript cookie. The correct PHP function is then loaded based on the cookie to display images at x2 or at their normal size.

syamilmj commented 11 years ago

Hi.

First of all, this is a brilliant idea for the resizer script.

However, my concern is that since the retina plugin & the cookie js is an alien element to the core functionality of the script, I think it would be more practical to just provide a hook (or hooks) which you can use to modify the values of the width/height?

I'm thinking of something like:

$width = apply_filter('aq_resize_width', $width);

and

$height = apply_filter('aq_resize_height', $height);

That way you can just use the hooks to modify the values from inside your custom script, e.g.

// ... check $pixel_ratio cookie here
if( $pixel_ratio >= 2 ){
     add_filter('aq_resize_width', function($width) { return $width * 2; } );
     add_filter('aq_resize_height', function($height) { return $height * 2; } );
}

What do you think?

mintplugins commented 11 years ago

Thanks :) aq is a great script - saved me a lot of time

Yeah thats a good idea. I think it would work. That way aq_resizer can remain as one script rather than needing to be 2 functions - right?

mintplugins commented 11 years ago

Oh ps - I also made a change on line 32 for the 2x function. It just checks to make sure the image that the user uploaded is big enough for 2x. If not than it doesn't change its size.

//if the image isn't big enough for 2x, put it back to 1x - philj
if($width > $orig_w || $height > $orig_h) { $width = $width/2;
$height = $height/2; }

ghostpool commented 11 years ago

Works great on one of my servers, but on my other server the page URL is cached, which means the retina script isn't working for retina devices (the page just continuously loads). Is there a workaround for this to possibly provide the server with a different URL to prevent caching?

wpexplorer commented 11 years ago

This is awesome Phil! Thanks for the update