Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[5.2] Validate Uploaded Image Dimensions#13428

Merged
taylorotwell merged 1 commit into
laravel:5.2from
themsaid:validate-image
May 9, 2016
Merged

[5.2] Validate Uploaded Image Dimensions#13428
taylorotwell merged 1 commit into
laravel:5.2from
themsaid:validate-image

Conversation

@themsaid
Copy link
Copy Markdown
Member

@themsaid themsaid commented May 4, 2016

This PR adds a new validation rule:

// Multiple rules
$rules = ['image' => 'image_dimensions:width=100,min_height=30'];

// Single rule
$rules = ['image' => 'image_dimensions:ratio=3/2'];

Available rules are:

  • min_width
  • min_height
  • max_width
  • max_height
  • width
  • height
  • ratio


if (isset($parameters['ratio'])) {
list($numerator, $denominator) = array_pad(sscanf($parameters['ratio'], '%d/%d'), 2, 1);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

eval?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeh, there's no way you need an eval in there

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I was using it for a different implementation but forgot to change. Will fix.

Sent from my iPhone

On May 4, 2016, at 9:09 PM, Graham Campbell [email protected] wrote:

In src/Illuminate/Validation/Validator.php:

  •    if (
    
  •        isset($parameters['width']) && $parameters['width'] != $width ||
    
  •        isset($parameters['min_width']) && $parameters['min_width'] > $width ||
    
  •        isset($parameters['max_width']) && $parameters['max_width'] < $width ||
    
  •        isset($parameters['height']) && $parameters['height'] != $height ||
    
  •        isset($parameters['min_height']) && $parameters['min_height'] > $height ||
    
  •        isset($parameters['max_height']) && $parameters['max_height'] < $height
    
  •    ) {
    
  •        return false;
    
  •    }
    
  •    if (isset($parameters['ratio'])) {
    
  •        list($numerator, $denominator) = array_pad(sscanf($parameters['ratio'], '%d/%d'), 2, 1);
    
  •        return eval("return {$numerator}/{$denominator};") == $width / $height;
    
    yeh, there's no way you need an eval in there


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

np ;)

@taylorotwell taylorotwell merged commit 2a487e4 into laravel:5.2 May 9, 2016
@taylorotwell
Copy link
Copy Markdown
Member

Guess we'll also need a new language line and docs entry for this.

@themsaid themsaid deleted the validate-image branch May 9, 2016 13:50
@themsaid
Copy link
Copy Markdown
Member Author

themsaid commented May 9, 2016

Will take care of that in a couple of hours :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants