Add filters to only process a particular intermediate image size in wp_generate_attachment_metadata().
421322
private function add_image_size_filters( $image_size ) {
		$image_size_filters = array();

		// For images.
		$image_size_filters['intermediate_image_sizes_advanced'] = function ( $sizes ) use ( $image_size ) {
			// $sizes is associative array of name => size info entries.
			if ( isset( $sizes[ $image_size ] ) ) {
				return array( $image_size => $sizes[ $image_size ] );
			}
			return array();
		};

		// For PDF previews.
		$image_size_filters['fallback_intermediate_image_sizes'] = function ( $fallback_sizes ) use ( $image_size ) {
			// $fallback_sizes is indexed array of size names.
			if ( in_array( $image_size, $fallback_sizes, true ) ) {
				return array( $image_size );
			}
			return array();
		};

		foreach ( $image_size_filters as $name => $filter ) {
			add_filter( $name, $filter, PHP_INT_MAX );
		}

		return $image_size_filters;
	}
1274878
def delete_attachment(request, link_field=None, uri=None):
    """"""
    if link_field is None:
        link_field = "record_uri"
    if uri is None:
        uri = record_uri(request)

    # Remove file.
    filters = [Filter(link_field, uri, core_utils.COMPARISON.EQ)]
    storage = request.registry.storage
    file_links, _ = storage.get_all("", FILE_LINKS, filters=filters)
    for link in file_links:
        request.attachment.delete(link['location'])

    # Remove link.
    storage.delete_all("", FILE_LINKS, filters=filters, with_deleted=False)
1201671
public function generate_srcset_and_sizes( $image, $attachment_id ) {
		// Ensure the image meta exists.
		$image_src = preg_match( '/src="([^"]+)"/', $image, $match_src ) ? $match_src[1] : '';

		list( $image_src ) = explode( '?', $image_src );

		// Return early if we couldn't get the image source.
		if ( ! $image_src ) {
			return $image;
		}

		// Select image size from classname starting with 'size-'.
		$img_size = preg_match( '/ size-([^\s"]+)/', $image, $match_size ) ? $match_size[1] : false;

		// Bailout if image size couldn’t be read.
		if ( ! $img_size ) {
			return $image;
		}

		// Maybe select replacement size.
		if ( ! empty( $this->args['map_sizes'] ) ) {
			if ( is_array( $this->args['map_sizes'] )
				&& in_array( $img_size, array_keys( $this->args['map_sizes'] ), true )
			) {
				$img_size = $this->args['map_sizes'][ $img_size ];
			} else {
				$img_size = $this->args['map_sizes'];
			}
		}

		// Get responsive image markup for srcset and sizes.
		$attributes = get_timber_image_attributes_responsive(
			$attachment_id,
			$img_size
		);

		// Bailout if markup couldn’t be generated.
		if ( ! $attributes ) {
			return $image;
		}

		// Remove existing src
		$image = preg_replace( '/ src="([^"]+)"/', '', $image );

		/**
		 * Remove width, height and alt attributes, because they are handled by
		 * get_timber_image_responsive_src().
		 *
		 * @see get_timber_image_responsive_src()
		 */
		$image = preg_replace( '/ height="([^"]+)"/', '', $image );
		$image = preg_replace( '/ width="([^"]+)"/', '', $image );
		$image = preg_replace( '/ alt="([^"]+)"/', '', $image );
		$image = preg_replace( '/ title="([^"]+)"/', '', $image );

		// Remove class attribute and save class attribute content in attributes array.
		if ( preg_match( '/ class="([^"]+)"/', $image, $class_matches ) ) {
			$attributes['class'] = $class_matches[1];
			$image               = preg_replace( '/ class="([^"]+)"/', '', $image );
		}

		/**
		 * Filters image attributes used for a responsive content image.
		 *
		 * @param array  $attributes    A key-value array of HTML attributes.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$attributes = apply_filters(
			'timmy/responsive_content_image/attributes',
			$attributes,
			$attachment_id,
			$img_size
		);

		// Replace image markup
		$image = preg_replace(
			'/<img ([^>]+?)[\/ ]*>/',
			'<img $1 ' . Helper::get_attribute_html( $attributes ) . ' />',
			$image
		);

		/**
		 * Filters the image HTML markup.
		 *
		 * This filter can be used to append content to an image.
		 *
		 * @param string $image         The image HTML markup.
		 * @param int    $attachment_id The attachment ID of the image.
		 * @param string $img_size      The image size key.
		 */
		$image = apply_filters(
			'timmy/responsive_content_image',
			$image,
			$attachment_id,
			$img_size
		);

		return $image;
	}
412128
function createSizeFilters(output, key, value) {
  // Store parameters
  var data = output.sizeData = output.sizeData || {};
  data[key] = value;

  if (!('size' in data)) {
    // No size requested, keep original size
    return [];
  }

  // Try to match the different size string formats
  var fixedSize = data.size.match(/([0-9]+)x([0-9]+)/);
  var fixedWidth = data.size.match(/([0-9]+)x\?/);
  var fixedHeight = data.size.match(/\?x([0-9]+)/);
  var percentRatio = data.size.match(/\b([0-9]{1,3})%/);
  var width, height, aspect;

  if (percentRatio) {
    var ratio = Number(percentRatio[1]) / 100;
    return [{
      filter: 'scale',
      options: {
        w: 'trunc(iw*' + ratio + '/2)*2',
        h: 'trunc(ih*' + ratio + '/2)*2'
      }
    }];
  } else if (fixedSize) {
    // Round target size to multiples of 2
    width = Math.round(Number(fixedSize[1]) / 2) * 2;
    height = Math.round(Number(fixedSize[2]) / 2) * 2;

    aspect = width / height;

    if (data.pad) {
      return getScalePadFilters(width, height, aspect, data.pad);
    } else {
      // No autopad requested, rescale to target size
      return [{ filter: 'scale', options: { w: width, h: height }}];
    }
  } else if (fixedWidth || fixedHeight) {
    if ('aspect' in data) {
      // Specified aspect ratio
      width = fixedWidth ? fixedWidth[1] : Math.round(Number(fixedHeight[1]) * data.aspect);
      height = fixedHeight ? fixedHeight[1] : Math.round(Number(fixedWidth[1]) / data.aspect);

      // Round to multiples of 2
      width = Math.round(width / 2) * 2;
      height = Math.round(height / 2) * 2;

      if (data.pad) {
        return getScalePadFilters(width, height, data.aspect, data.pad);
      } else {
        // No autopad requested, rescale to target size
        return [{ filter: 'scale', options: { w: width, h: height }}];
      }
    } else {
      // Keep input aspect ratio

      if (fixedWidth) {
        return [{
          filter: 'scale',
          options: {
            w: Math.round(Number(fixedWidth[1]) / 2) * 2,
            h: 'trunc(ow/a/2)*2'
          }
        }];
      } else {
        return [{
          filter: 'scale',
          options: {
            w: 'trunc(oh*a/2)*2',
            h: Math.round(Number(fixedHeight[1]) / 2) * 2
          }
        }];
      }
    }
  } else {
    throw new Error('Invalid size specified: ' + data.size);
  }
}
81666
function(size) {
    return function limitResolution(params) {
      var height = params.height;
      if (height) {
        var requiredPixels = pixelRatio() * height;
        var minFov = 2 * Math.atan(requiredPixels / size);
        params.fov = clamp(params.fov, minFov, Infinity);
      }
      return params;
    };
  }
757077
private function addImageSizes()
    {
        $data = $this->getData();
        foreach ($data as $slug => $props)
        {
            add_image_size($slug, $props['width'], $props['height'], $props['crop']);
        }
    }
60187
protected function registerImageSizes()
    {
        do_action("before_theme_register_image-sizes");

        foreach ($this->getConfig("image-sizes") as $id => $data):
            add_image_size($id, $data["width"], $data["height"], $data["crop"]);
        endforeach;

        do_action("after_theme_register_image-sizes");
    }
427223
def _image_filter(self, filter=None, size=2):
        
        from numpy import isscalar
        from scipy.ndimage.filters import median_filter, uniform_filter

        FILTERS = {
            'median': median_filter,
            'uniform': uniform_filter
        }

        func = FILTERS[filter]

        mode = self.mode
        value_shape = self.value_shape
        ndims = len(value_shape)

        if ndims == 3 and isscalar(size) == 1:
            size = [size, size, size]

        if ndims == 3 and size[2] == 0:
            def filter_(im):
                if mode == 'spark':
                    im.setflags(write=True)
                else:
                    im = im.copy()
                for z in arange(0, value_shape[2]):
                    im[:, :, z] = func(im[:, :, z], size[0:2])
                return im
        else:
            filter_ = lambda x: func(x, size)

        return self.map(lambda v: filter_(v), value_shape=self.value_shape)
474055
private function update_attachment_metadata_for_image_size( $id, $new_metadata, $image_size ) {
		$metadata = wp_get_attachment_metadata( $id );

		if ( ! is_array( $metadata ) ) {
			return false;
		}

		// If have metadata for image_size.
		if ( ! empty( $new_metadata['sizes'][ $image_size ] ) ) {
			$metadata['sizes'][ $image_size ] = $new_metadata['sizes'][ $image_size ];
			wp_update_attachment_metadata( $id, $metadata );
			return true;
		}

		// Else remove unused metadata if any.
		if ( ! empty( $metadata['sizes'][ $image_size ] ) ) {
			unset( $metadata['sizes'][ $image_size ] );
			wp_update_attachment_metadata( $id, $metadata );
			// Treat removing unused metadata as no change.
		}
		return false;
	}
926835
def addFilter(self, filterclass):
        """"""
        if filterclass not in self.filters:
            self.filters.append(filterclass)
1243352
private function loadImageToEditPath( $attachment_id, $size = 'full' ) {
        $filepath = get_attached_file( $attachment_id );

        if ( $filepath && file_exists( $filepath ) ) {
            if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) {
                $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size );
            }
        } elseif ( function_exists( 'fopen' ) && true == ini_get( 'allow_url_fopen' ) ) {
            $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size );
        }
        return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size );
    }
152259
public function removePortraitImage()
    {
        $sizes = $this->_mixer->getValue('sizes');

        if (empty($sizes)) {
            $sizes = explode(' ', 'original large medium small thumbnail square');
        } else {
            $sizes = array_keys($sizes);
        }

        foreach ($sizes as $size) {
            $file = $this->_mixer->getPortraitFile($size);
            $this->_mixer->deletePath($file);
        }

        $this->set('filename', null);
    }
721651
private void CheckTransparencyMask(IfdTags metadata, int n) {
    // Samples per pixel
    if (!metadata.containsTagId(TiffTags.getTagId("SamplesPerPixel"))) {
      validation.addErrorLoc("Missing Samples Per Pixel", "IFD" + n);
    } else {
      long spp = metadata.get(TiffTags.getTagId("SamplesPerPixel")).getFirstNumericValue();
      if (spp != 1) {
        validation.addError("Invalid Samples Per Pixel", "IFD" + n, spp);
      }
    }

    // BitsPerSample
    if (!metadata.containsTagId(TiffTags.getTagId("BitsPerSample"))) {
      validation.addErrorLoc("Missing BitsPerSample", "IFD" + n);
    } else {
      long bps = metadata.get(TiffTags.getTagId("BitsPerSample")).getFirstNumericValue();
      if (bps != 1) {
        validation.addError("Invalid BitsPerSample", "IFD" + n, bps);
      }
    }
  }
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)
381763
public function add_image_sizes_meta_to_media($form_meta, $post = null)
    {
        if (wp_attachment_is_image($post->ID) && current_user_can('manage_options')) {
            $meta = wp_get_attachment_metadata($post->ID);

            $form_meta .= '<strong>Available sizes: </strong>' . \count($meta['sizes']);
        }

        return $form_meta;
    }
1081068
private void convertLargeParts() {

        List<Attachment> newAttachments = new ArrayList<>();

        if (!publicParts.isEmpty()) {
            try {

                List<Part> toLarge = new ArrayList<>();
                for (Part p : publicParts) {
                    if (p.getData() != null && p.getData().length() > maxPartSize) {
                        String type = p.getType() != null ? p.getType() : "application/octet-stream";
                        newAttachments.add(Attachment.create(p.getData(), type, Attachment.LOCAL_AUTO_CONVERTED_FOLDER, p.getName()));
                        toLarge.add(p);
                        log.w("Message part " + p.getName() + " to large (" + p.getData().length() + ">" + maxPartSize + ") - converting to attachment.");
                    }
                }
                if (!toLarge.isEmpty()) {
                    publicParts.removeAll(toLarge);
                }

            } catch (Exception e) {
                log.f("Error when removing large message parts", e);
            }
        }

        attachments.addAll(newAttachments);
    }
758768
function prepareAttachmentForJS($response, $attachment, $meta) {
		if(!$response || empty($response) || !isset($response['sizes'])) {
			return $response;
		}

		if($this->renderPDF && isset($meta['s3'])) {
			if($attachment->post_mime_type == 'application/pdf') {
				$response['type'] = 'image';
				$response['mime'] = 'image/pdf';
				if(isset($meta['width'])) {
					$response['width'] = round($meta['width']);
				}

				if(isset($meta['height'])) {
					$response['height'] = round($meta['height']);
				}

				if(isset($response['width']) && isset($response['height'])) {
					$response['orientation'] = ($response['width'] > $response['height']) ? 'landscape' : 'portrait';
				}
			}
		}

		$generateUrls = !($this->skipGifs && ($attachment->post_mime_type == 'image/gif'));
		if ($generateUrls) {
            foreach($response['sizes'] as $key => $sizeInfo) {
                $res = $this->buildImgixImage($response['id'], $key);
                if(is_array($res)) {
                    $response['sizes'][$key]['url'] = $res[0];
                }
            }
        }

		return $response;
	}