PDA

View Full Version : Download Full Size Image From Another URL



grizgza
01-09-2013, 01:26 AM
Hello,

Would it be possible to have "Download' link to the full-size image, rather than the image that is linked to in the gallery? I have the gallery thumbnails link to 1024xXXX images for loading speed purposes. I would like the "Download" link in Social Gallery to link to the full-size copy of the image, not the 1024xXXX versions.

Any ideas?

Thanks
Justin

grizgza
01-09-2013, 01:28 AM
This is the code in the functions.php file of my theme that changes the image size for the gallery images:


//Make attachements load large images in gallery, rather than full size
function oikos_get_attachment_link_filter( $content, $post_id, $size, $permalink ) {

// Only do this if we're getting the file URL
if (! $permalink) {
// This returns an array of (url, width, height)
$image = wp_get_attachment_image_src( $post_id, 'large' );
$new_content = preg_replace('/href=\'(.*?)\'/', 'href=\'' . $image[0] . '\'', $content );
return $new_content;
}
}

add_filter('wp_get_attachment_link', 'oikos_get_attachment_link_filter', 10, 4);

woods
01-09-2013, 03:16 PM
Hi Justin,

This will need some customisation to the plugin because by default it's not so clever. I'll add it to the list of possible futures :)

grizgza
01-10-2013, 02:05 AM
Understood. I think this feature would be very beneficial for photo/portfolio sites that upload high resolution (2MB+) photos to their site. Loading the smaller size versions (100-500KB) in lightbox for speed makes a lot of sense, while providing full download access via the link.

In the meantime for my purposes, I updated the Social Gallery JS to .slice the last 13 characters (eg. "-1024x700.jpg") and add back on the ".jpg" to the string variable d (download link).

Cheers!

woods
01-16-2013, 01:24 PM
Hi grizgza,

Nice solution! Though other users please note that this may not work for you - Grizgza has a very setup environment and he knows exactly what he's doing!

Glad you solved it though, for sure I'd like to add a better solution for downloading - as it stands it loads the image if you left click download and I can force it to actually just prompt you with a "save as..." dialog, I just haven't got round to adding it yet. I'll consider your problem when I hit that :)



Cheers Grizgza!

grizgza
01-16-2013, 03:53 PM
Hi grizgza,

Nice solution! Though other users please note that this may not work for you - Grizgza has a very setup environment and he knows exactly what he's doing!

Glad you solved it though, for sure I'd like to add a better solution for downloading - as it stands it loads the image if you left click download and I can force it to actually just prompt you with a "save as..." dialog, I just haven't got round to adding it yet. I'll consider your problem when I hit that :)



Cheers Grizgza!

Yes, I don't recommend mucking around in core plugin code unless you really need to and know exactly what you're doing. :)

I'd be interested if you figure out a good solution for the "save as..." thing. I had been using code in my .htaccess file to do this, but it was interfering with Facebook's crawlers reading Open Graph meta information, specifically the images. Since all .jpg files on my site were triggering the 'save as' instead of opening normally. Apparently, this affected the Facebook crawlers too. This was also a global site-wide solution too, which wouldn't work for anyone anyways. But here it is in case anyone wants to play around with it.



<FilesMatch "\.(?i:jpg)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>


Note: I have not tested this with Social Gallery, but I was using it with my old lightbox.

woods
01-17-2013, 12:55 PM
Grizgza,

Again - awesomely useful share - thanks very much for taking the time.

This is a good solution and is ultimately what I'll build into Social Gallery, I have a plan how I'll do it in my head and maybe if I have time I'll get it into v2.1!





Thanks again Grizgza!


Woody