WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Add more image sizes (22 posts)

  1. valfreixo
    Member
    Posted 5 years ago #

    Howdy.

    I'm creating a site about music with interviews, video and photo galleries among other features. It's a very elaborate them with almost all been customized and tailored.

    troughout the template, I'm using several image sizes. When I upload an image, QP creates 3 image sizes. The problem is that I need around 10 diferent sizes. Is there any plugin I can use to do this? Or a way to extend worpdress in way I can code several additional image sizes?

    Thank you in advance

    Zen

  2. valfreixo
    Member
    Posted 5 years ago #

    Guys, sorry about the bump. But I'm really stuck on this.

    Thank you for any direction. Not looking for the complete solution. Just for a direction were I can start building it

  3. Shane G
    Member
    Posted 5 years ago #

    Hi,

    Its better that you can change image sizes from the coding area and set the image size upon the requirement.

    [signature moderated Please read the Forum Rules]

  4. valfreixo
    Member
    Posted 5 years ago #

    I'm building this site for reporters that cover music events. They have like 30 or 40 photos each day. I'm just looking for a way to create all the sizes previously just to ease on the work.

    All the photos have the 9 by 6 ratio so every image resized will be a perfect fit. Also can't stretch/contract image sizes because they simply don't want it. Tough huh?

    Thank you for your time in helping me out

    Zen

  5. valfreixo
    Member
    Posted 5 years ago #

    Ok, found the solution

  6. jlubeck
    Member
    Posted 5 years ago #

    Please share your solution with us so that someone trying to do the same can benefit from it. Thanks!

  7. kath
    Member
    Posted 5 years ago #

    I'm also asking you to post your solution! I could really use this feature.

  8. Aesqe
    Member
    Posted 5 years ago #

    try something like this:

    if( FALSE === get_option("frontpage_size_w") )
    {
    	add_option("frontpage_size_w", "260");
    	add_option("frontpage_size_h", "0");
    	add_option("frontpage_size_crop", "0");
    }
    else
    {
    	update_option("frontpage_size_w", "260");
    	update_option("frontpage_size_h", "0");
    	update_option("frontpage_size_crop", "0");
    }
    
    function additional_image_sizes( $sizes )
    {
    	$sizes[] = "frontpage";
    
    	return $sizes;
    }
    add_filter( 'intermediate_image_sizes', 'additional_image_sizes' );

    the above example will add size called "frontpage" to the list of image sizes. for each additional image size, you will have to add its name to the $sizes array and add its width, height and crop values to wp's options.

    like this:

    if( FALSE === get_option("frontpage_size_w") )
    {
    	add_option("frontpage_size_w", "260");
    	add_option("frontpage_size_h", "0");
    	add_option("frontpage_size_crop", "0");
    
    	add_option("anothersize_size_w", "260");
    	add_option("anothersize_size_h", "0");
    	add_option("anothersize_size_crop", "0");
    }
    else
    {
    	update_option("frontpage_size_w", "260");
    	update_option("frontpage_size_h", "0");
    	update_option("frontpage_size_crop", "0");
    
    	update_option("anothersize_size_w", "260");
    	update_option("anothersize_size_h", "0");
    	update_option("anothersize_size_crop", "0");
    }
    
    function additional_image_sizes( $sizes )
    {
    	$sizes[] = "frontpage";
    	$sizes[] = "anothersize";
    
    	return $sizes;
    }
    add_filter( 'intermediate_image_sizes', 'additional_image_sizes' );

    you can put this code in the functions.php file, or create a plugin out of it.

    cheers ;)

  9. Aesqe
    Member
    Posted 5 years ago #

    also, i've recently discovered this awesome plugin called "scissors", which allows you to crop image after upload via javascript, and it really works very well :)

  10. Aesqe
    Member
    Posted 5 years ago #

    correction: when setting crop option, it should be written like this:

    add_option("anothersize_crop", "0");

    instead of:

    add_option("anothersize_size_crop", "0");

    no need for "_size" after size name and before "_crop", sorry about that.

  11. vafa
    Member
    Posted 5 years ago #

    can we change the image size name?
    (from imagename-333x222.jpg to imagename-medium.jpg)

  12. MK009
    Member
    Posted 5 years ago #

    aesqe, I can't get your code to work with 2.8. Really looking for this functionality, has 2.8 possibly changed the filter or something?

  13. onel0ve
    Member
    Posted 5 years ago #

    without upload can i resize image ?.like i post image link of tinypic ?? then

  14. MK009
    Member
    Posted 5 years ago #

    onel0ve, if you hotlink the image hosted on tinypic then resize it with html you can. You would do this just from the post screen.

  15. Aesqe
    Member
    Posted 5 years ago #

    MK009:

    the code works, but you won't see the sizes in the admin interface - check your uploads folder to see the result, that is different sizes of uploaded images.

    or if i misunderstood you, please explain a bit further so i may be of assistance :)

  16. MK009
    Member
    Posted 5 years ago #

    Woohoo, thanks aesqe. This will sort out all image chopping for my project. :D

    And definitely worth noting that there won't be any additions to the admin interface.

  17. stevecb
    Member
    Posted 5 years ago #

    This is a great script aesqe, thanks very much.
    As I hoped, if the uploaded image is smaller than one of the specified sizes, that size is skipped.

    However I would like to be able to get a list of the available sizes for a particular image, anyone know how this can be done?

    Cheers.

  18. stevecb
    Member
    Posted 5 years ago #

    I supposed I could use if statements to check the image is available in a certain size.

    if (wp_get_attachment_image_src($attachment->ID, 'image_size_name') {
       //display
    }

    It's not ideal, but should do the job.

  19. alkafy
    Member
    Posted 4 years ago #

    @aesqe - Thank you for sharing. Exactly what I needed.

  20. waltervos
    Member
    Posted 4 years ago #

    I've written a plugin based on this thread. It allows you to easily define additional image sizes, to generate new copies of earlier uploaded pictures and you can also use the newly defined image sizes when editing a post.

    You can find it here: http://wordpress.org/extend/plugins/additional-image-sizes/

  21. Aesqe
    Member
    Posted 4 years ago #

    thank you, waltervos, your plugin is a lifesaver :)

  22. waltervos
    Member
    Posted 4 years ago #

    @aesqe: That's good to hear, thanks! Please let me know if you find any bugs (just start a thread about it with the tag additional-image-sizes) or if you have feature requests.

Topic Closed

This topic has been closed to new replies.

About this Topic