WordPress.org

Ready to get started?Download WordPress

Forums

image_make_intermediate_size (3 posts)

  1. mores
    Member
    Posted 5 years ago #

    Hello,

    I just realized there is a way to get medium sized images to be zoomcropped to fit the exact measurements you set in your WordPress options.

    Now, I'd like to make this optional.
    If it's a landscape mode pic, zoomcrop it, if it's a portrait mode, then don't.

    I believe it has something to do with image_make_intermediate_size. Now, I don't want to edit any core files, so I'm looking for a way to hook into that and do some height/width calculations before it's being executed.

  2. mores
    Member
    Posted 5 years ago #

    I tried using this in my functions.php:

    function dm_image_make_intermediate_size($file, $width, $height, $crop=false) {
    	if ( $width || $height ) {
    		if ($width >> $height) {$crop=true;}
    		$resized_file = image_resize($file, $width, $height, $crop);
    		if ( !is_wp_error($resized_file) && $resized_file && $info = getimagesize($resized_file) ) {
    			$resized_file = apply_filters('image_make_intermediate_size', $resized_file);
    			return array(
    				'file' => basename( $resized_file ),
    				'width' => $info[0],
    				'height' => $info[1],
    			);
    		}
    	}
    	return false;
    }
    add_filter('image_make_intermediate_size', 'dm_image_make_intermediate_size', 11, 4);

    But I get an error message saying there's parameter 2 and 3 missing.

  3. Alignak
    Member
    Posted 5 years ago #

    well, I'm having the same problem...
    Have you figure it out yet?

Topic Closed

This topic has been closed to new replies.

About this Topic