Hey all,
I have the need to grab the HREF value from a link to an image, parse it, append it with “[COLOR=”DarkRed”]-144×127
for use as the src for a dynamic thumbnail. I have the following worked out, but… surely there’s a better way?
[code=php]
// ex. HREF
// url http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set.jpg
if(jQuery(‘div.pods_field_photo>div>a’).first().length>0)
{ photo_url = jQuery(‘.pods_field_photo>div>a’).first().attr(‘href’);
photo_name = basename(photo_url);
path = photo_url.split(photo_name);
splt_thmb = photo_name.split(‘.’)
src = path[0]+splt_thmb[0]+’-144×127.’+splt_thmb[1];
} else src = jQuery(‘#no_image’).val();
jQuery(‘#pre_load_src’).val(src);
jQuery(‘.pre_load’).attr(‘src’,src);
function basename(path) {
return path.replace(/\/g,’/’).replace( /.*//, ” );
}
// src = http://www.alternamart.org/demox/wp-content/uploads/2011/08/honeybake_baking_set-114×127.jpg
Of course it would be a lot easier to split on the file extension, but I won’t necessarily know whether the file is a GIF, PNG, JPEG… so…?
Any thoughts?