WordPress.org

Support

Support » Plugins and Hacks » [Plugin: User Photo] [feature request] Image dimension

[Plugin: User Photo] [feature request] Image dimension

  • Sisir
    Participant

    @prionkor

    Not sure if it can be done in current version so let me know if i can do it with current version.

    Maximum dimension will be break apart in two part. Max width and Max height. This will work like how wordpress native image thumbnails works.

    1. When Max Width and Max Height box input is given the plugin will hard crop the image to the given size.
    2. When only Width or Height given wordpress will soft crop the image meaning the Height or Width (which field is blank) will be decided according to proportion.

    Hope it make sense. I believe we will see it in near future 🙂

    http://wordpress.org/extend/plugins/user-photo/

Viewing 6 replies - 1 through 6 (of 6 total)
  • +1 for this. Soft cropping is essential for many layouts.

    I’ve decided to hack this plugin for the project I’m working on. It seems to be rarely updated, which reduces the hassle of re-applying changes repeatedly. And maybe this code can be included in the next release?

    Basically I’ve altered the resizing so that the thumbnail is always soft-cropped to a square. The main image is resized proportionately. I think all this really needs to be incorporated into the official release is a new option, a “Crop” checkbox for the thumbnail (and maybe the main image too). Then these options can be worked into the following code as appropriate.

    This code replaces line 865 – 886 of user-photo.php (version 0.9.5.2).

    // Initialize resizing
    $src_x = $src_y = 0;
    $image_width = $src_w = $info[0];
    $image_height = $src_h = $info[1];
    
    if ( $maxdimension == get_option( 'userphoto_thumb_dimension' ) ) {
    
    	// Thumbnail - crop to square
    	$image_new_height = $image_new_width = $maxdimension;
    	if ( $image_width > $image_height ) {
    		$src_x = ( $image_width - $image_height ) / 2;
    		$src_w = $image_height;
    	} else {
    		$src_y = ( $image_height - $image_width ) / 2;
    		$src_h = $image_width;
    	}
    
    } else {
    
    	// Main image resize - proportionate
    	if ( $image_width > $image_height ) {
    		$image_new_width = $maxdimension;
    		$image_ratio = $image_width / $image_new_width;
    		$image_new_height = $image_height / $image_ratio;
    	} else {
    		$image_new_height = $maxdimension;
    		$image_ratio = $image_height / $image_new_height;
    		$image_new_width = $image_width / $image_ratio;
    	}
    
    }
    
    $imageresized = imagecreatetruecolor( $image_new_width, $image_new_height);
    @ imagecopyresampled( $imageresized, $image, 0, 0, $src_x, $src_y, $image_new_width, $image_new_height, $src_w, $src_h );

    I would also love to see the dimension passed to get_avatar() respected when overriding that function. Right now it is just picking the closest of the thumbnail or full size. Doing a soft resize if a dimension is passed would be much better.

    Hi Steve it sounds interesting but i can´t make it work.
    Could you specify where to place the code?

    My line 865 starts with $error = sprintf(__(“Unable to place the user photo at: %s”, ‘user-photo’), $imagepath);

    }

    thank you.

    @xjavier, that’s line 433 for me. Sounds like something to do with differences in how our editors are handling line breaks!

    To be clear, this is the chunk of code in the original plugin that the above code should replace:

    // figure out the longest side
    
    if ( $info[0] > $info[1] ) {
    	$image_width = $info[0];
    	$image_height = $info[1];
    	$image_new_width = $maxdimension;
    
    	$image_ratio = $image_width / $image_new_width;
    	$image_new_height = $image_height / $image_ratio;
    	//width is > height
    } else {
    	$image_width = $info[0];
    	$image_height = $info[1];
    	$image_new_height = $maxdimension;
    
    	$image_ratio = $image_height / $image_new_height;
    	$image_new_width = $image_width / $image_ratio;
    	//height > width
    }
    
    $imageresized = imagecreatetruecolor( $image_new_width, $image_new_height);
    @ imagecopyresampled( $imageresized, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $info[0], $info[1] );

    It works!, in my case i need the main image

    userphoto_full_dimension

    to calculate it´s width as the maximum dimension because im working with rectangles (250 x 172),

    thanks @steve

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: User Photo] [feature request] Image dimension’ is closed to new replies.