Apply filter to resource
        :param resource: Image
        :return: Image
974294
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        original_width, original_height = resource.size

        if self.start[0] < original_width or self.start[1] < original_height:
            left = self.start[0]
            upper = self.start[1]
        else:
            left = 0
            upper = 0

        right = self.start[0] + self.size[0]
        lower = self.start[1] + self.size[1]

        resource_format = resource.format
        resource = resource.crop(
            (
                left,
                upper,
                right if right < original_width else original_width,
                lower if lower < original_height else original_height
            )
        )
        resource.format = resource_format

        return resource
875057
def remove_image(self, image, force=False, noprune=False):
        
        params = {'force': force, 'noprune': noprune}
        res = self._delete(self._url("/images/{0}", image), params=params)
        return self._result(res, True)
981664
def get(self, resource, params=None, headers=None):
        
        return self.do(resource, 'GET', params=params, headers=headers)
1109715
def feed(self, image):
        
        network_name = self.__class__.__name__.lower()

        with tf.variable_scope(network_name):
            return self._feed(image)
292054
def compile_resource(resource):
    
    return re.compile("^" + trim_resource(re.sub(r":(\w+)", r"(?P<\1>[\w-]+?)",
                      resource)) + r"(\?(?P<querystring>.*))?$")
270842
public function applyFilter(Image $image)
    {
        $image->fit($this->params["w"], $this->params["h"]);

        return $image;
    }
611153
def resource_index
      if self.class.included_modules.include? APPI::FiltersResources
        apply_filter_params resource_class.all
      else
        resource_class.all
      end
    end
1177083
def image(
        rendered_path: str,
        width: int = None,
        height: int = None,
        justify: str = None
) -> str:
    """"""
    environ.abort_thread()
    return templating.render_template(
        'image.html',
        path=rendered_path,
        width=width,
        height=height,
        justification=(justify or 'left').lower()
    )
1244022
def Filter(self, filename_spec):
    """"""
    if "@" in filename_spec:
      file_path, package_name = filename_spec.split("@")
    else:
      file_path, package_name = filename_spec, Resource.default_package

    resource_path = package.ResourcePath(package_name, file_path)
    if resource_path is not None:
      return resource_path


    # pylint: disable=unreachable
    raise FilterError(
        "Unable to find resource %s while interpolating: " % filename_spec)
1374366
public function apply($resource){
		// Extract arguments
		@list(,$mask,$xinit,$yinit)=func_get_args();
		if(is_subclass_of($mask,'Imagix\AbstractImage')){
			$mask=$mask->getResource();
		}
		elseif(!is_resource($mask)){
			throw new Exception("The 'mask' parameter must be a valid GD resource or a Lumy_File_Image child object");
		}
		// Prepare
		$w_mask=imagesx($mask);
		$h_mask=imagesy($mask);
		if($w_mask===false || $h_mask===false){
			throw new Exception("An error was encountered while getting mask image resolution");
		}
		$width=imagesx($resource);
		$height=imagesy($resource);
		if($width===false || $height===false){
			throw new Exception("An error was encountered while getting source image resolution");
		}
		$xinit=(int)$xinit;
		$yinit=(int)$yinit;
		if($xinit<0)				$xinit=0;
		if($xinit>$width-$w_mask)	$xinit=$width-$w_mask;
		if($yinit<0)				$yinit=0;
		if($yinit>$height-$h_mask)	$yinit=$height-$h_mask;
		// Create new image
		$image=$this->_createTrueColor($width,$height);
		if(!imagecopy($image,$resource,0,0,0,0,$width,$height)){
			throw new Exception("Cannot copy image");
		}
		// Modify colors
		$x=$xinit;
		do{
			$y=$yinit;
			do{
				// Get pixel color from source image
				$rgba_src=$this->_getColorAt($image,$x,$y);
				// Get pixel color from mask image
				$rgba_mask=$this->_getColorAt($mask,$x-$xinit,$y-$yinit);
				// Generate alpha
				if($rgba_mask[0]==$rgba_mask[1] && $rgba_mask[1]==$rgba_mask[2]){
					$alpha=floor($rgba_mask[0]/2)+$rgba_src[3];
					if($alpha>127) $alpha=127;
				}
				else{
					throw new Exception("Mask image must be in grayscale");
				}
				// Define new pixel
				$color=imagecolorallocatealpha($image,$rgba_src[0],$rgba_src[1],$rgba_src[2],$alpha);
				if($color===false){
					throw new Exception("Cannot allocate color");
				}
				if(!imagesetpixel($image,$x,$y,$color)){
					throw new Exception("Cannot set pixel");
				}
			}
			while(++$y<$h_mask+$yinit);
		}
		while(++$x<$w_mask+$xinit);
		return $image;
	}
286010
def map_to_data_element(self, resource):
        
        trv = ResourceTreeTraverser(resource, self.as_pruning())
        visitor = DataElementBuilderResourceTreeVisitor(self)
        trv.run(visitor)
        return visitor.data_element
525776
def lookup_image(wildcard):
  

  ec2 = get_ec2_resource()
  filter_ = {'Name': 'name', 'Values': [wildcard]}

  images = list(ec2.images.filter(Filters=[filter_]))

  # Note, can add filtering by Owners as follows
  #  images = list(ec2.images.filter_(Filters = [filter_], Owners=['self', 'amazon']))

  assert len(images) <= 1, "Multiple images match " + str(wildcard)
  assert len(images) > 0, "No images match " + str(wildcard)
  return images[0]
948261
def apply(self, resource):
        
        if not isinstance(resource, Image.Image):
            raise ValueError('Unknown resource format')

        original_width, original_height = resource.size

        resource_format = resource.format

        if self.mode == 'outbound':
            target_width, target_height = self.outbound_sizes(original_width, original_height, self.width, self.height)
            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)

            crop_sizes = self.crop_sizes(target_width, target_height, self.width, self.height)
            resource = resource.crop(crop_sizes)
        else:
            target_width, target_height = self.inset_sizes(original_width, original_height, self.width, self.height)
            resource = resource.resize((target_width, target_height), Image.ANTIALIAS)

        resource.format = resource_format

        return resource
855124
def remove_uri(self, image):
        '''
        '''
        image = image or ''
        uri = self.get_uri(image) or ''
        image = image.replace('%s://' %uri,'', 1)
        return image.strip('-').rstrip('/')
698242
public function apply($resource){
		// Extract arguments
		@list(,$w_ratio,$h_ratio,$position)=func_get_args();
		$w_ratio=(float)$w_ratio;
		$h_ratio=(float)$h_ratio;
		if($w_ratio<=0 or $h_ratio<=0){
			throw new Exception("Ratio cannot be null or negative");
		}
		// Get resolution
		$w_src=imagesx($resource);
		$h_src=imagesy($resource);
		if($w_src===false or $h_src===false){
			throw new Exception("An error was encountered while getting image resolution");
		}
		// Compute basic chop dimensions
		$w_tmp=round(($h_src/$h_ratio)*$w_ratio);
		$h_tmp=round(($w_src/$w_ratio)*$h_ratio);
		if($w_tmp>$h_tmp){
			$width=$w_src;
			$height=$h_tmp;
		}
		else{
			$width=$w_tmp;
			$height=$h_src;
		}
		// Compute position
		switch($position){
			case self::LEFT:
				$x=0;
				if($w_ratio<$h_ratio)		$y=0;
				elseif($w_ratio>$h_ratio)	$y=round(($h_src-$height)/2);
				else						$y=round(($h_src-$height)/2);
				break;
			case self::RIGHT:
				$x=$w_src-$width;
				if($w_ratio<$h_ratio)		$y=0;
				elseif($w_ratio>$h_ratio)	$y=round(($h_src-$height)/2);
				else						$y=round(($h_src-$height)/2);
				break;
			case self::TOP:
				if($w_ratio<$h_ratio)		$x=round(($w_src-$width)/2);
				elseif($w_ratio>$h_ratio)	$x=0;
				else						$x=round(($w_src-$width)/2);
				$y=0;
				break;
			case self::BOTTOM:
				if($w_ratio<$h_ratio)		$x=round(($w_src-$width)/2);
				elseif($w_ratio>$h_ratio)	$x=0;
				else						$x=round(($w_src-$width)/2);
				$y=$h_src-$height;
				break;
			case self::CENTERED:
			default:
				if($w_ratio<$h_ratio){
					$x=round(($w_src-$width)/2);
					$y=0;
				}
				elseif($w_ratio>$h_ratio){
					$x=0;
					$y=round(($h_src-$height)/2);
				}
				else{
					$x=round(($w_src-$width)/2);
					$y=round(($h_src-$height)/2);
				}
		}
		// Chop image
		return parent::apply($resource,$x,$y,$width,$height);
	}
871153
def image_tasks(self):
        
        uri = "/%s/tasks" % self.uri_base
        resp, resp_body = self.api.method_get(uri)
        return resp_body
1047738
def _get_or_add_image(self, image_file):
        
        image_part, rId = self.part.get_or_add_image_part(image_file)
        desc, image_size = image_part.desc, image_part._px_size
        return rId, desc, image_size