Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add image size (width,height) validator #263

Open
jovicaj opened this issue Aug 6, 2018 · 2 comments
Open

Add image size (width,height) validator #263

jovicaj opened this issue Aug 6, 2018 · 2 comments

Comments

@jovicaj
Copy link

jovicaj commented Aug 6, 2018

Hello
Is there an option to check image width and height?

@deba12
Copy link

deba12 commented Oct 29, 2018

I hacked up something like this bellow

public function validate_image_size($field, $input, $param = null) {
	if (!isset($input[$field])) {
		return;
	}
	if (is_array($input[$field]) && $input[$field]['error'] !== 4) {
		$size = explode(';', $param);
		$image_info = getimagesize($input[$field]['tmp_name']);
		if(($image_info[0] <= $size[0]) && $image_info[1] <= $size[1]) {
			return;
		}
		return array(
			'field' => $field,
			'value' => $input[$field],
			'rule' => __FUNCTION__,
			'param' => $param,
		);
	}
}

and validation rule:

	$this->validate->validation_rules(array(
		'file'		=> 'required_file|image_size,768;90'
	));

@telemoes
Copy link

telemoes commented May 16, 2019

Is it not beter to make a new function for this with gump::add_validator?
because when you update your script the changes are gone.

GUMP::add_validator('image_size', function ($field, $input, $param){ if (!isset($input[$field])) { return; } if (is_array($input[$field]) && $input[$field]['error'] !== 4) { $size = explode(';', $param); $image_info = getimagesize($input[$field]['tmp_name']); if(($image_info[0] <= $size[0]) && $image_info[1] <= $size[1]) { return; } return [ 'field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param, ]; } });

@filisko filisko changed the title Image size Add image size (width,height) validator Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants