Validate image input.
540287
def get(img, cache_dir=CACHE_DIR, iterative=False):
    """"""
    if os.path.isfile(img):
        wal_img = img

    elif os.path.isdir(img):
        if iterative:
            wal_img = get_next_image(img)

        else:
            wal_img = get_random_image(img)

    else:
        logging.error("No valid image file found.")
        sys.exit(1)

    wal_img = os.path.abspath(wal_img)

    # Cache the image file path.
    util.save_file(wal_img, os.path.join(cache_dir, "wal"))

    logging.info("Using image \033[1;37m%s\033[0m.", os.path.basename(wal_img))
    return wal_img
913527
def _validate(self,val):
        """"""
        if isinstance(self.class_, tuple):
            class_name = ('(%s)' % ', '.join(cl.__name__ for cl in self.class_))
        else:
            class_name = self.class_.__name__
        if self.is_instance:
            if not (isinstance(val,self.class_)) and not (val is None and self.allow_None):
                raise ValueError(
                    "Parameter '%s' value must be an instance of %s, not '%s'" %
                    (self.name, class_name, val))
        else:
            if not (val is None and self.allow_None) and not (issubclass(val,self.class_)):
                raise ValueError(
                    "Parameter '%s' must be a subclass of %s, not '%s'" %
                    (val.__name__, class_name, val.__class__.__name__))
872207
def check_image_is_3d(img):
    """"""

    if len(img.shape) < 3:
        raise ValueError('Input volume must be atleast 3D!')
    elif len(img.shape) == 3:
        for dim_size in img.shape:
            if dim_size < 1:
                raise ValueError('Atleast one slice must exist in each dimension')
    elif len(img.shape) == 4:
        if img.shape[3] != 1:
            raise ValueError('Input volume is 4D with more than one volume!')
        else:
            img = np.squeeze(img, axis=3)
    elif len(img.shape) > 4:
        raise ValueError('Invalid shape of image : {}'.format(img.shape))

    return img
1195519
function validate(inputs, options) {
    let hasError = false

    if (inputs.length >= 2) {
        console.error("ERROR: the input file should not be multiple.")
        hasError = true
    }
    if (inputs.length >= 1 && !fs.existsSync(inputs[0])) {
        console.error("ERROR: the input file should exist.")
        hasError = true
    }
    if (options.output != null && Array.isArray(options.output)) {
        console.error("ERROR: --output option should not be multiple.")
        hasError = true
    }
    if (inputs.length >= 1 && options.output != null && path.resolve(inputs[0]) === path.resolve(options.output)) {
        console.error("ERROR: --output option should not be the same as the input file.")
        hasError = true
    }
    if (options.manifest != null && Array.isArray(options.manifest)) {
        console.error("ERROR: --manifest option should not be multiple.")
        hasError = true
    }

    return !hasError
}
602507
def check_image_is_4d(img, min_num_volumes=2):
    """"""

    if len(img.shape) < 4:
        raise ValueError('Input volume must be 4D!')
    elif len(img.shape) == 4:
        for dim_size in img.shape[:3]:
            if dim_size < 1:
                raise ValueError('Atleast one slice must exist in each dimension')
        if img.shape[3] < min_num_volumes:
            raise ValueError('Input volume is 4D '
                             'with less than {} volumes!'.format(min_num_volumes))
    elif len(img.shape) > 4:
        raise ValueError('Too many dimensions : more than 4.\n'
                         'Invalid shape of image : {}'.format(img.shape))

    return img
34692
def assert_valid_input(cls, tag):
        """"""

        # Fail on unexpected types.
        if not cls.is_tag(tag):
            raise TypeError("Expected a BeautifulSoup 'Tag', but instead recieved type {}".format(type(tag)))
165444
def validate(self, value):
        """"""
        if value is not None and not isinstance(value, str):
            raise ValidationError("field must be a string")

        super().validate(value)
647526
def IsImage(self, filename):
		""""""
		mimetype =  mimetypes.guess_type(filename)[0]
		if not mimetype:
			return False
		return mimetype.startswith("image/")
1341133
def _validate_input(self, table: pd.DataFrame, failed_only=False) -> pd.DataFrame:
        """"""
        return self._do_validation_set(
            table=table,
            columns=self.input_columns,
            validation_type="input",
            failed_only=failed_only,)
1165450
def validate(self, instance, value):
        """"""
        if isinstance(value, string_types):
            value = COLORS_NAMED.get(value, value)
            if value.upper() == 'RANDOM':
                value = random.choice(COLORS_20)
            value = value.upper().lstrip('#')
            if len(value) == 3:
                value = ''.join(v*2 for v in value)
            if len(value) != 6:
                self.error(instance, value, extra='Color must be known name '
                           'or a hex with 6 digits. e.g. "#FF0000"')
            try:
                value = [
                    int(value[i:i + 6 // 3], 16) for i in range(0, 6, 6 // 3)
                ]
            except ValueError:
                self.error(instance, value,
                           extra='Hex color must be base 16 (0-F)')
        if not isinstance(value, (list, tuple)):
            self.error(instance, value,
                       extra='Color must be a list or tuple of length 3')
        if len(value) != 3:
            self.error(instance, value, extra='Color must be length 3')
        for val in value:
            if not isinstance(val, integer_types) or not 0 <= val <= 255:
                self.error(instance, value,
                           extra='Color values must be ints 0-255.')
        return tuple(value)
753858
protected function isValid($image)
    {
        $this->validateOptions();

        if (!$image instanceof ImageInterface) {
            $this->addError('The given value was not an Image instance.', 1327943859);
            return;
        }
        if (isset($this->options['minimumWidth']) && $image->getWidth() < $this->options['minimumWidth']) {
            $this->addError('The actual image width of %1$d is lower than the allowed minimum width of %2$d.', 1319801362, [$image->getWidth(), $this->options['minimumWidth']]);
        } elseif (isset($this->options['maximumWidth']) && $image->getWidth() > $this->options['maximumWidth']) {
            $this->addError('The actual image width of %1$d is higher than the allowed maximum width of %2$d.', 1319801859, [$image->getWidth(), $this->options['maximumWidth']]);
        }
        if (isset($this->options['minimumHeight']) && $image->getHeight() < $this->options['minimumHeight']) {
            $this->addError('The actual image height of %1$d is lower than the allowed minimum height of %2$d.', 1319801925, [$image->getHeight(), $this->options['minimumHeight']]);
        } elseif (isset($this->options['maximumHeight']) && $image->getHeight() > $this->options['maximumHeight']) {
            $this->addError('The actual image height of %1$d is higher than the allowed maximum height of %2$d.', 1319801929, [$image->getHeight(), $this->options['maximumHeight']]);
        }

        if (isset($this->options['minimumResolution']) || isset($this->options['maximumResolution'])) {
            $resolution = $image->getWidth() * $image->getHeight();
            if (isset($this->options['minimumResolution']) && $resolution < $this->options['minimumResolution']) {
                $this->addError('The given image size of %1$d x %2$d is too low for the required minimum resolution of %3$d.', 1319813336, [$image->getHeight(), $image->getHeight(), $this->options['minimumResolution']]);
            } elseif (isset($this->options['maximumResolution']) && $resolution > $this->options['maximumResolution']) {
                $this->addError('The given image size of %1$d x %2$d is too high for the required maximum resolution of %3$d.', 1319813355, [$image->getHeight(), $image->getHeight(), $this->options['maximumResolution']]);
            }
        }
    }
126585
def main(input_file, output, format):
    """"""

    try:
        process_image(input_file, subfolder=output, ext=format)
    except Exception as e:
        sys.exit(e)
26153
def image_format(value):
    

    if value.image.format.upper() not in constants.ALLOWED_IMAGE_FORMATS:
        raise ValidationError(MESSAGE_INVALID_IMAGE_FORMAT)
524427
public function validate( $input )
    {
        // Check if we got readaccess to the provided file name at all.
        if ( !is_file( $input ) || !is_readable( $input ) )
        {
            throw new phpillowRuntimeException( 'Given image file not found: ' . $input );
        }

        // Use getimagesize to determine the filetype of the image, and compare
        // with whitelist of supported image formats.
        $imageData = getimagesize( $input );
        if ( ( $imageData === false ) ||
             ( !in_array( $imageData[2], $this->supportedImageFormats ) ) )
        {
            throw new phpillowValidationException( 'Unsupported image format provided.', array() );
        }

        // If all checks passed, we assume that this is a proper image file.
        return $input;
    }
994654
def _validated(self, data):
        """"""
        for sub in self.schemas:
            data = sub(data)
        return data
1209393
def validate_input(self):
        
        self.exposure_layer = layer_from_combo(self.dock.exposure_layer_combo)
        self.hazard_layer = layer_from_combo(self.dock.hazard_layer_combo)
        self.aggregation_layer = layer_from_combo(
            self.dock.aggregation_layer_combo)

        is_valid = True
        warning_message = None
        if self.exposure_layer is None:
            warning_message = tr(
                'Exposure layer is not found, can not save scenario. Please '
                'add exposure layer to do so.')
            is_valid = False

        if self.hazard_layer is None:
            warning_message = tr(
                'Hazard layer is not found, can not save scenario. Please add '
                'hazard layer to do so.')
            is_valid = False

        return is_valid, warning_message
1265839
def validate_items(self, input_list):
        """"""
        output_list = []
        for item in input_list:
            valid = self.list_item_type.validate(item, self.item_name)
            output_list.append(valid)

            # this might lead to confusing error messages.  tbh, we need to
            # figure out a better way to do validation and error handling here,
            # but i'm brute forcing this a bit so that we have something
            # workable
        return output_list