WordPress.org

Ready to get started?Download WordPress

Forums

Force crop to Medium size (6 posts)

  1. Norke
    Member
    Posted 5 years ago #

    I have searched before asking. I found a few plugins and forumposts, but they aren't working for 2.7 yet. I hope there might be a quick hack or maybe I missed a plugin or post.

    I would like to have 75x75 and 225x225 thumbnails (If it's possible, I could also use 150x150 but I can use the 225x225 thumb for it.)

    I tried changing line 147 in wp-includes/media.php
    function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=false) {
    to
    function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop=true) {
    but I don't think it' working.

    I hope someone can help me on the right direction. Thank you :)

    Yannick

  2. Aesqe
    Member
    Posted 5 years ago #

    you don't need to hack the code, you just have to change the medium size crop option from 0 to 1, which you can do from your functions.php file, or by writing a plugin.

    placing something like this inside your functions.php should do the trick:

    if(!get_option("medium_size_crop")
        add_option("medium_size_crop", "1");
    else
        update_option("medium_size_crop", "1");

    also take a look at this topic if you wish to add more image sizes to your wp installation.

  3. Aesqe
    Member
    Posted 5 years ago #

    sorry, pasted the wrong option again, argh, should be:

    if(!get_option("medium_crop")
        add_option("medium_crop", "1");
    else
        update_option("medium_crop", "1");
  4. mores
    Member
    Posted 5 years ago #

    aesque ... when I paste this code into a functions.php, I get an error ... could you tell me how to implement this properly?

    EDIT: there's a bracket missing in the first line. Should be

    if(!get_option("medium_crop"))
        add_option("medium_crop", "1");
    else
        update_option("medium_crop", "1");

    Now if only I could find a way to do this only for landscape format images, and leave the portraits the way they are ....

  5. Aesqe
    Member
    Posted 5 years ago #

    oops sorry about that :o

    also, i've learned recently, it's better to check an option's existence with

    if(false === get_option())

    than with

    if(!get_option("medium_crop"))

    because the second version will also return false (equal to true, that is) if option is there, but empty.

    mores: i'll look into it, it all depends on the order in which functions are executed.

  6. mores
    Member
    Posted 5 years ago #

    Thanks, for looking into the portrait/landscape thing and the info on the option-checking!

Topic Closed

This topic has been closed to new replies.

About this Topic