Skip to content

Add size ratio to the output of wp media image-size#58

Merged
danielbachhuber merged 3 commits intowp-cli:masterfrom
runofthemill:#56-add-size-ratio-to-image-size-output
Dec 15, 2017
Merged

Add size ratio to the output of wp media image-size#58
danielbachhuber merged 3 commits intowp-cli:masterfrom
runofthemill:#56-add-size-ratio-to-image-size-output

Conversation

@runofthemill
Copy link
Contributor

@runofthemill runofthemill commented Dec 14, 2017

Fixes #56

Copy link
Member

@schlessera schlessera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I provided two suggestions to improve maintainability in comments.

Also, the spacing and alignment is completely off, please make sure the formatting adheres to the WordPress Coding Standards.

$height_ratio = $height / $gcd;
$image_ratio = "{$width_ratio}:{$height_ratio}";
}
return $image_ratio;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should prefer early returns instead of else clauses.
Something like this:

if ( $height == 0 ) {
   return "0:{$width}";
}

if ( $width == 0 ) {
   return "{$height}:0";
}

$gcd          = $this->gcd( $width, $height );
$width_ratio  = $width / $gcd;
$height_ratio = $height / $gcd;
return "{$width_ratio}:{$height_ratio}";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @schlessera for the quick review! I'll take a look tomorrow and adjust :)

'width' => intval( get_option( 'large_size_w' ) ),
'height' => intval( get_option( 'large_size_h' ) ),
'crop' => false !== get_option( 'large_crop' ) ? 'hard' : 'soft',
'ratio' => false !== get_option( 'large_crop' ) ? $this->get_ratio( intval( get_option( 'large_size_w' ) ), intval( get_option( 'large_size_h' ) ) ) : 'N/A',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we're using the string 'N/A' multiple times here, you should put it into a constant and refer to the constant instead.

This way, if we want to change the value to display for these cases, we can do it consistently and without running the risk of missing one or more instances.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should put it into a constant and refer to the constant instead.

Variable — constants are globally scoped.

@danielbachhuber danielbachhuber modified the milestone: 1.1.3 Dec 14, 2017
@danielbachhuber danielbachhuber added command:media Related to 'media' command command:media-image-size Related to 'media image-size' command labels Dec 14, 2017
@runofthemill
Copy link
Contributor Author

@schlessera @danielbachhuber comments addressed, and formatting fixed as well.

@danielbachhuber danielbachhuber added this to the 1.1.3 milestone Dec 15, 2017
@danielbachhuber danielbachhuber merged commit 5bd517b into wp-cli:master Dec 15, 2017
@danielbachhuber
Copy link
Member

Thanks @runofthemill !

@runofthemill runofthemill deleted the #56-add-size-ratio-to-image-size-output branch December 15, 2017 18:57
danielbachhuber added a commit that referenced this pull request Nov 18, 2022
…size-output

Add size ratio to the output of wp media image-size
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:media Related to 'media' command command:media-image-size Related to 'media image-size' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants