• Hi

    I am trying to make a post with some images in it. Some of them are portrait so I want them smaller (eg. 60%) but when I change the size in the post editor the images all come out full size on my blog.

    If you look at the html of the post on the blog you can see that the image width and height has been changed but the image displays full size. Clearing the cache makes no difference.

    More details: the images are all sized so that the landscape ones are the size I want them displayed (660×442), I add them to the post using the ‘add media’ button, then edit the portrait ones by clicking on them and resizing to say 60%.

    Has anyone else had this problem or have any ideas? Any help much appreciated!

    Thanks.

Viewing 1 replies (of 1 total)
  • alicjazurawie

    (@alicjazurawie)

    Hello,

    (ETA: I just re-read your question, and it seems that your images are being resized okay, so please just skip to my suggestion re: css at the bottom. I’m leaving the first bits up in case they help any other members.)

    If you would like all of the images on your site to display at 640px width (both for landscape and portrait shots), it would probably be best if you resized them before uploading to WordPress. The media controls in WordPress can be a bit clunky at times, and it’s best to do resizing beforehand.

    Alternatively, you could (a) go to settings > media and change the size of the ‘large’ image on upload, (b) use a plugin to automatically resize images when they upload (so that the original file is deleted and only the resized images are kept) or (c) add a line of code to your functions.php to do the same thing as a plugin.

    I have used the following within my functions.php file in order to accomplish (c) :

    // Automatically resize the original image to 'large' dimensions, then delete original
    
    function replace_uploaded_image($image_data) {
        // if there is no large image : return
        if (!isset($image_data['sizes']['large'])) return $image_data;
    
        // paths to the uploaded image and the large image
        $upload_dir = wp_upload_dir();
        $uploaded_image_location = $upload_dir['basedir'] . '/' .$image_data['file'];
        $large_image_location = $upload_dir['path'] . '/'.$image_data['sizes']['large']['file'];
    
        // delete the uploaded image
        unlink($uploaded_image_location);
    
        // rename the large image
        rename($large_image_location,$uploaded_image_location);
    
        // update image metadata and return them
        $image_data['width'] = $image_data['sizes']['large']['width'];
        $image_data['height'] = $image_data['sizes']['large']['height'];
        unset($image_data['sizes']['large']);
    
        return $image_data;
    }
    add_filter('wp_generate_attachment_metadata','replace_uploaded_image');

    If none of the above work, then it could be an issue with your css… your images may be coded such that they will stretch to fit a div. In which case, you would need to change your style.css file so that images display at width: 100%; OR max-width: 100%;

    I am new to helping out on these forums, so I hope my response has been of some help and hasn’t further confused matters.

Viewing 1 replies (of 1 total)
  • The topic ‘Images won't resize’ is closed to new replies.