The MU forums have moved to WordPress.org

The right way to set default thumbnail size? (21 posts)

  1. boonika
    Member
    Posted 15 years ago #

    1. I have found these lines inside wp-admin/includes/image.php:

    function wp_shrink_dimensions( $width, $height, $wmax = 170, $hmax = 120 ) {
    	return wp_constrain_dimensions( $width, $height, $wmax, $hmax );

    2. I have also found these lines inside wp-includes/media.php:
    ` elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
    $max_width = intval(get_option('thumbnail_size_w'));
    $max_height = intval(get_option('thumbnail_size_h'));
    // last chance thumbnail size defaults
    if ( !$max_width && !$max_height ) {
    $max_width = 128;
    $max_height = 96;
    }
    } `

    Which one of those two files should I edit and what exactly do I need to do to change default thumbnail size?

    3. Of course, I also want my thumbs to be cropped automatically so I'm wondering is it the right way to achieve that by changing 'false' values into 'true' values in this image.php line:

    function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
    	if ( is_numeric( $src_file ) ) // Handle int as attachment ID
    		$src_file = get_attached_file( $src_file );
  2. boonika
    Member
    Posted 15 years ago #

    Anyone?

  3. andrea_r
    Moderator
    Posted 15 years ago #

    In the next release the thumbnails are bigger. :)

  4. boonika
    Member
    Posted 15 years ago #

    Thanks A.

    I wrote wrong values in that first code. Those are values that I'm currently using. Default are 128 and 96. No one answered so I changed values in both files. Testing my luck.

    Still don't know what is the right way to enable 'crop' by default.

  5. boonika
    Member
    Posted 15 years ago #

    For others.

    So I changed values in both files and it's not working. At least not for me. Default thumb size for newly created blogs stays 128 x 96 px. That's all. Cheers.

  6. boonika
    Member
    Posted 15 years ago #

    Hmmm... maybe it will work if I edit file before I run WPMU installation. It doesn't sound logical to me but that's all can do now... no I'm not crying for help:)

  7. musnake
    Member
    Posted 15 years ago #

    ...and you choose not to set the default values via the admin backend (get_option('thumbnail_size_w'))because...? You're trying to do something without using the thumbnail values set by the admin user?

  8. boonika
    Member
    Posted 15 years ago #

    I want the same thumb size for all blogs that are about to be created so admins don't have to do by themselves.

  9. musnake
    Member
    Posted 15 years ago #

    Ah, as I recall, the WPMu New Blog Options plugin allowed you to hardcode the settings for future blogs in the plugin's code...

    Recently updated to 2.6 too!

  10. boonika
    Member
    Posted 15 years ago #

    Well thanks a lot... a looooooooot. I'll check that link.

  11. jamescollins
    Member
    Posted 15 years ago #

    Hi boonika,

    It looks like the thumbnail settings are stored in the following wp_options:

    thumbnail_size_w
    thumbnail_size_h
    thumbnail_crop

    So, creating an mu-plugin with the following code in it should do the trick:

    add_action('wpmu_new_blog', 'my_new_blogs_settings');
    
    function my_new_blogs_settings($blog_id) {
        update_option('thumbnail_size_w', '150');
        update_option('thumbnail_size_h', '150');
        update_option('thumbnail_crop', '');
    }

    Change 150 to whatever you want. The thumbnail_crop option is either a 1 or empty, depending on whether you want to have the checkbox ticked (value = 1) or not (value = empty string).

    The wpmu_new_blog action is executed whenever a new blog is created (after the default settings have been set).

  12. boonika
    Member
    Posted 15 years ago #

    Thanks James. I'll try that when I get some sleep.

    Cheers

  13. boonika
    Member
    Posted 15 years ago #

    Nothing happened:(

    This is how mu-plugin looks like looks:

    <?php
    /*
    Plugin Name: Default Thumb Size
    Plugin URI: http://mu.wordpress.org/forums/topic.php?id=8974
    Description: Sets deffault thumb size for new profiles.
    Version: 0.1
    Author:
    Author URI:
    */
    
    add_action('wpmu_new_blog', 'my_new_blogs_settings');
    
    function my_new_blogs_settings($blog_id) {
        update_option('thumbnail_size_w', '170');
        update_option('thumbnail_size_h', '120');
        update_option('thumbnail_crop', '1');
    }
    ?>
  14. musnake
    Member
    Posted 15 years ago #

    Try this, as per wp-admin/includes/schema.php:

    <?php
    /*
    Plugin Name: Default Thumb Size
    Plugin URI: http://mu.wordpress.org/forums/topic.php?id=8974
    Description: Sets deffault thumb size for new profiles.
    Version: 0.1
    Author:
    Author URI:
    */
    
    add_action('wpmu_new_blog', 'my_new_blogs_settings');
    
    function my_new_blogs_settings($blog_id) {
        update_option('thumbnail_size_w', 170);
        update_option('thumbnail_size_h', 120);
        update_option('thumbnail_crop', 1);
    }
    ?>
  15. boonika
    Member
    Posted 15 years ago #

    Hmmm... I didn't understand you quite well. And what is the difference between our codes? I can't detect it myself. Thanks in advance.

  16. musnake
    Member
    Posted 15 years ago #

    I stripped the single quotes from around the second update_option parameter...

    update_option('thumbnail_size_w', 170);

    So, 170 instead of '170' although the function definition for update_option shows both values as strings...

    I went with the stock file that 'works' under my setup (paste from my core files)... although I completely agree with James' version which is codex-compliant.

  17. boonika
    Member
    Posted 15 years ago #

    Oooo... now I see:) I'll try it and let you know what happens. Thanks.

  18. boonika
    Member
    Posted 15 years ago #

    Nope:(

  19. boonika
    Member
    Posted 15 years ago #

    OK, problem solved... kind off. I've changed values inside
    wp-admin/includes/schema.php

    Musnake, thanks for pointing me to schema.php

    I've edited wrong files previously. Still, I would prefer plugin solution.

  20. dsader
    Member
    Posted 15 years ago #

    Boonika, this will work as mu-plugin with WPMU2.6.

    add_action('populate_options', 'my_new_blog_settings');
    function my_new_blog_settings($blog_id) {
        add_option('thumbnail_size_w', 170);
        add_option('thumbnail_size_h', 120);
        add_option('thumbnail_crop', 1);
    }
  21. boonika
    Member
    Posted 15 years ago #

    @dsader
    I'll try that when I upgrade but I think I'll wait for 2.6.1.

    Btw, you've helped me SO much in last few months and I already have a plan on how to return a favor. If I forget please do remind me. Cafespain and andrea_r also helped with some simple solutions. Also, thanks to all other members for their useful and un-useful replys... even to luna(sarcastic)byte:D

    THANKS A LOT

About this Topic