Checks whether an image size is restricted to certain post types.

@param array        $img_size             Image configuration array.
@param string|array $attachment_post_type Post type for attachment.

@return bool
768871
public static function is_size_for_post_type( $img_size, $attachment_post_type ) {
		if ( ! is_array( $attachment_post_type ) ) {
			$attachment_post_type = array( $attachment_post_type );
		}

		// Reset post types that should be applied as a standard
		$post_types_to_apply = array( '', 'page', 'post' );

		/**
		 * When a post type is given in the arguments, we generate the size
		 * only if the attachment is associated with that post.
		 */
		if ( array_key_exists( 'post_types', $img_size ) ) {
			$post_types_to_apply = $img_size['post_types'];
		}

		if ( ! in_array( 'all', $post_types_to_apply, true ) ) {
			// Check if we should really resize that picture
			$intersections = array_intersect( $post_types_to_apply, $attachment_post_type );

			if ( ! empty( $intersections ) ) {
				return true;
			}
		} else {
			return true;
		}

		return false;
	}
311170
public static function max_upload_size()
    {
        // find max filesize value
        $max_filesize = parse_bytes(ini_get('upload_max_filesize'));
        $max_postsize = parse_bytes(ini_get('post_max_size'));

        if ($max_postsize && $max_postsize < $max_filesize) {
            $max_filesize = $max_postsize;
        }

        return $max_filesize;
    }
201901
public static function allowImportItem($postdata) {
        $cc_types = array('application/vnd.ims.imsccv1p1',
            'application/vnd.ims.imsccv1p2', 'application/vnd.ims.imsccv1p3');
        if ( ! isset($postdata['content_item_return_url']) ) return false;
        if ( isset($postdata['accept_media_types']) ) {
            $accept = $postdata['accept_media_types'];

            foreach($cc_types as $cc_mimetype ){
                $m = new Mimeparse;
                $cc_allowed = $m->best_match(array($cc_mimetype), $accept);
                if ( $cc_mimetype == $cc_allowed ) return true;
            }
        }
        return false;
    }
314948
public function isImage($mimeType)
    {
        $isValid = false;

        $allowedType = array('image/jpeg' , 'image/png' ,'image/gif');

        if (\in_array($mimeType, $allowedType)) {
            $isValid = true;
        }

        return $isValid;
    }
48157
public function enable_custom_image_sizes($sizes)
    {
        // Merge custom sizes into $sizes.
        $sizes = \array_merge($sizes, $this->size_dropdown_names);

        // Ensure 'Full size' is always at end.
        unset($sizes['full']);
        unset($sizes['thumbnail']);

        if (Config::get('images.insert_image_allow_full_size') || empty($sizes)) {
            $sizes['full'] = 'Full Size';
        }

        return $sizes;
    }
868516
public function validateDimensions($attribute, $value, $parameters)
    {
        if ($this->isValidFileInstance($value) && $value->getClientMimeType() === 'image/svg+xml') {
            return true;
        }

        if (! $this->isValidFileInstance($value) || ! $sizeDetails = @getimagesize($value->getRealPath())) {
            return false;
        }

        $this->requireParameterCount(1, $parameters, 'dimensions');

        [$width, $height] = $sizeDetails;

        $parameters = $this->parseNamedParameters($parameters);

        if ($this->failsBasicDimensionChecks($parameters, $width, $height) ||
            $this->failsRatioCheck($parameters, $width, $height)) {
            return false;
        }

        return true;
    }
680326
function image($img_url, $x, $y, $w, $h, $resolution = "normal") {
    $w = (int)$w;
    $h = (int)$h;

    $img_type = Image_Cache::detect_type($img_url);
    $img_ext  = Image_Cache::type_to_ext($img_type);

    if ( isset($this->_imgs[$img_url]) ) {
      $img = $this->_imgs[$img_url];
    }
    else {
      $img = $this->_imgs[$img_url] = $this->_pdf->load_image($img_type, $img_url, "");
    }

    $y = $this->y($y) - $h;
    $this->_pdf->fit_image($img, $x, $y, "boxsize=\{$w $h\} fitmethod=entire");
  }
1263031
protected function check_is_post_type_allowed( $post_type ) {
		if ( ! is_object( $post_type ) ) {
			$post_type = get_post_type_object( $post_type );
		}

		if ( ! empty( $post_type ) && ! empty( $post_type->show_in_rest ) ) {
			return true;
		}

		return false;
	}
37079
public function getImageWidth($type, $size)
	{
		if (empty($this->$type))
		{
			return null;
		}
		$method = $this->getImageConfig($type, $size, 'method');

		// Width varies for images that are 'portrait', 'auto', 'fit', 'crop'
		if (in_array($method, array('portrait', 'auto', 'fit', 'crop')))
		{
			list($width) = $this->getImageDimensions($type, $size);
			return $width;
		}
		return $this->getImageConfig($type, $size, 'width');
	}
230512
public static function dimensions($input, $type, $size) {
        if (static::file($input)) {
            $input = $input['tmp_name'];
        }

        if (!file_exists($input)) {
            return false;
        }

        if ($file = getimagesize($input)) {
            $width = $file[0];
            $height = $file[1];

            switch ($type) {
                case 'width':       return ($width == $size);
                case 'height':      return ($height == $size);
                case 'maxWidth':    return ($width <= $size);
                case 'maxHeight':   return ($height <= $size);
                case 'minWidth':    return ($width >= $size);
                case 'minHeight':   return ($height >= $size);
            }
        }

        return false;
    }
1324394
public static function _delete_generated_if_image( $post_id ) {
		if ( wp_attachment_is_image($post_id) ) {
			$attachment = new Image($post_id);
			if ( $attachment->file_loc ) {
				ImageHelper::delete_generated_files($attachment->file_loc);
			}
		}
	}
489996
private function timber_generate_sizes( $attachment_id ) {
		$sizes      = [];
		$img_sizes  = Helper::get_image_sizes();
		$attachment = get_post( $attachment_id );

		/**
		 * Never automatically generate image sizes on upload for SVG and GIF images.
		 * SVG and GIF images will still be resized when requested on the fly.
		 */
		if ( in_array( $attachment->post_mime_type, array(
			'image/svg+xml',
			'image/gif',
		), true ) ) {
			return $sizes;
		}

		// Timber needs the file src as an URL
		$file_src  = wp_get_attachment_url( $attachment_id );
		$meta_data = wp_get_attachment_metadata( $attachment_id );

		/**
		 * Delete all existing image sizes for that file.
		 *
		 * This way, when Regenerate Thumbnails will be used, all non-registered image sizes will be
		 * deleted as well. Because Timber creates image sizes when they’re needed, we can safely do
		 * this.
		 */
		Timber\ImageHelper::delete_generated_files( $file_src );

		foreach ( $img_sizes as $key => $img_size ) {
			if ( ! $this->timber_should_resize( $attachment->post_parent, $img_size ) ) {
				continue;
			}

			// Create downsized version of the image
			$downsized = image_downsize( $attachment_id, $key );

			// Bail out if there was an error while downsizing the image.
			if ( ! is_array( $downsized ) ) {
				continue;
			}

			list( $file_src, $file_width, $file_height ) = $downsized;

			/**
			 * Create an image definition array that will be used for attachment metadata.
			 *
			 * WordPress saves an array with the file src, the width, the height and the mime type
			 * of an attachment in the postmeta database table. By generating this array and saving
			 * it in the database, we can improve the compatibility with the core image
			 * functionality.
			 *
			 * Correct width and height values of '0' by calculating them from the original image
			 * ratio, if meta data is available.
			 */
			if ( ! empty( $meta_data['height'] ) && ! empty( $meta_data['width'] ) ) {
				if ( 0 === (int) $file_width && ! empty( $meta_data['height'] ) ) {
					$file_width = round( $file_height / $meta_data['height'] * $meta_data['width'] );
				} elseif ( 0 === (int) $file_height ) {
					$file_height = round( $file_width / $meta_data['width'] * $meta_data['height'] );
				}
			}

			if ( is_numeric( $file_width ) && is_numeric( $file_height ) ) {
				$sizes[ $key ] = [
					'file'      => wp_basename( $file_src ),
					'width'     => $file_width,
					'height'    => $file_height,
					'mime-type' => wp_check_filetype( $file_src )['type'],
				];
			}

			/**
			 * Filters whether srcset sizes should be generated when an image is uploaded.
			 *
			 * @since 0.13.0
			 *
			 * @param bool     $generate_srcset_sizes Whether to generate srcset sizes. Passing false will prevent
			 *                                        srcset sizes to generated when an image is uploaded. Default false.
			 * @param string   $key                   The image size key.
			 * @param array    $img_size              The image size configuration array.
			 * @param \WP_Post $attachment            The attachment post.
			 */
			$generate_srcset_sizes = apply_filters( 'timmy/generate_srcset_sizes', false, $key, $img_size, $attachment );

			// Get setting from image configuration.
			$generate_srcset_sizes = isset( $img_size['generate_srcset_sizes'] )
				? $img_size['generate_srcset_sizes']
				: $generate_srcset_sizes;

			if ( false === $generate_srcset_sizes ) {
				continue;
			}

			// Get values for the default image
			$crop  = Helper::get_crop_for_size( $img_size );
			$force = Helper::get_force_for_size( $img_size );

			// Generate additional image sizes used for srcset
			if ( isset( $img_size['srcset'] ) ) {
				foreach ( $img_size['srcset'] as $srcset_size ) {
					list( $width, $height ) = Helper::get_dimensions_for_srcset_size( $img_size['resize'], $srcset_size );

					// For the new source, we use the same $crop and $force values as the default image
					self::resize( $img_size, $file_src, $width, $height, $crop, $force );
				}
			}
		}

		return $sizes;
	}
924882
public function handleImageOptimizer($postId) {
	    $this->processingOptimized = true;

	    Logger::info('Handle Image Optimizer: '.$postId);


        add_filter('ilab_ignore_existing_s3_data', function($shouldIgnore, $attachmentId) use ($postId) {
            if ($postId == $attachmentId) {
                return true;
            }

            return $shouldIgnore;
        }, 10000, 2);

        $this->processImport(1,  $postId, null);
    }
777106
public static function get_image_fields( $field, $attachment_id, $sub_field = false ) {
		$size = apply_filters( Filter::IMAGE, false, $field, $sub_field );

		if ( ! $size ) {
			return $attachment_id;
		}

		$src = wp_get_attachment_image_src( $attachment_id, $size );

		if ( ! $src ) {
			return $attachment_id;
		}

		return [
			'src' 		=> $src[0],
			'width'		=> $src[1],
			'height'	=> $src[2],
			'alt'		=> get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ),
		];
	}
1064750
public function getImageCalSize($imagesize=array(),$image_config=array())
    {
        $r = array();
        if(count($imagesize)>0 && isset($imagesize[0],$imagesize[1]) && count($image_config)>0){
            if ($image_config[2]===true && $image_config[3]===null) {
                $por =  $image_config[0] / $imagesize[0];
                $height = round($imagesize[1] * $por);
                $r[0] = $image_config[0];
                $r[1] = $height;
            }elseif ($image_config[2]===null && $image_config[3]===true) {
                $por =  $image_config[1] / $imagesize[1];
                $width = round($imagesize[0] * $por);
                $r[0] = $width;
                $r[1] = $image_config[1];
            }else{
                $r[0] = $image_config[0];
                $r[1] = $image_config[1];
            }
        }
        return $r;
    }
908480
private function validateImageMimeType()
    {
        $imageType = exif_imagetype($this->uploadFile->getTemporaryFilename());
        $mime = image_type_to_mime_type($imageType);
        if (!$imageType || !in_array($mime, parent::getAllowedMimeTypes())) {
            throw new \Exception("Uploaded image appears to be corrupt"); // @codeCoverageIgnore
        }
    }
1328881
public static function getAcceptImageMimeTypes()
    {
        $imageAllowFiles = Yii::$app->getSettings()->get('imageAllowFiles','attachment');
        $extensions = explode(',', $imageAllowFiles);
        array_walk($extensions, function (&$value) {
            $value = 'image/' . $value;
        });
        return $extensions;
    }