[wp-hackers] add_image_size() possible to restrict to just one size?..

Davit Barbakadze jayarjo at gmail.com
Mon Sep 6 07:09:56 UTC 2010


Every add_image_size creates another image. I've got a pile of various
unused sizes for every image I upload. Huge waste of space.

On Mon, Sep 6, 2010 at 10:39 AM, Patrik Bóna <patrik.bona at mrhead.sk> wrote:
> Hi Mike,
>
> Yes i am replacing thumbnail size with that line. To be honest on that site
> from which is this code, thumbnail size is not even set, but it doesn't
> matter. I have different post types on that site and i don't need to
> generate same image sizes for each post type, so this is my solution...
>
> I think that best would be to change add_image_size, so it would be possible
> to register image size just for one post type, not for whole site, but
> perhaps somebody else should do it, because i am not sure how ;).
>
> Btw. this is code for deleting all image sizes:
>
> function delete_all_sizes($attachment_id) {
>        $metadata = wp_get_attachment_metadata($attachment_id);
>        if(!$metadata)
>                return false;
>        $upload_dir = wp_upload_dir();
>        $subdir = dirname($metadata['file']);
>        foreach($metadata['sizes'] as $size) {
>                $file = $upload_dir['basedir'] . '/' . $subdir . '/' .
> $size['file'];
>                if(file_exists($file)&&  is_file($file))
>                        unlink($file);
>        }
> }
> add_action('delete_attachment', 'delete_all_sizes');
>
> Patrik
>
> On 09/05/2010 11:39 PM, Mike Schinkel wrote:
>>
>> I have one question though, on this line:
>>
>>
>>>
>>> >       $metadata['sizes']['thumbnail'] = array('file' =>
>>> > basename($file), 'width' =>   100, 'height' =>   100);
>>>
>>
>> Are you replacing the thumbnail with your custom size?  I'm unclear on
>> what you are attempting to achieve here (maybe because I'm not 100% clear
>> how WordPress' image handling all works, but not for lack of inspecting the
>> code that does image handling.)
>>
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Davit Barbakadze


More information about the wp-hackers mailing list