Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm looking for a method to create an instance of add_image_size();

To elaborate: I am using the file uploader in a plugin to insert a file reference by ID. That ID is then used to create touch icons for the site <meta>.

But I want to downsize the image to various sizes (57x57px, 72x72px, and 114x114px) on the fly. I don't however want to create a new image size for every attachment image, just this one instance.

right now wp_get_attachment_image_src($id, array(57, 57)) and wp_get_attachment_image_src($id, array(72, 72)) return the same url.

Could I add_image_size() in my function, return the images, and then unset the function?

Anyone have any thoughts?

share|improve this question
add comment

2 Answers 2

Look at this

http://www.studiograsshopper.ch/code-snippets/remove-wordpress-defaultmedia-image-sizes/

function sgr_filter_image_sizes( $sizes) {

    unset( $sizes['thumbnail']);
    unset( $sizes['medium']);
    unset( $sizes['large']);

    return $sizes;
}
add_filter('intermediate_image_sizes_advanced', 'sgr_filter_image_sizes');

You need to hijack it using global $your ID....

share|improve this answer
add comment

When you upload an image, it's saved, and a copy is created for every image size, resized to the appropriate dimensions.

When you specify a set of dimensions manually, e.g.

wp_get_attachment_image_src($id, array(57, 57)) 

the 57x57 dimensions are compared to the image sizes, and the nearest image size is chosen and that image is returned. So for that to work you'd need to define image sizes for each stage.

From your question I believe you want WordPress to generate these when they're first requested though, not on upload.

If so, this plugin will do the trick:

http://wordpress.org/extend/plugins/wp-thumb/

It replaces the image handling internally. With that installed image handling should work a lot closer to what you're expecting, e.g. you would get a 57px by 57px image not the nearest size

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.