Un motore di ricerca WordPress per sviluppatori e autori di temi



wp_create_image_subsizes ›

Da5.3.0
Deprecaton/a
wp_create_image_subsizes ( $file, $image_meta, $attachment_id )
Parametri: (3)
  • (string) $file Full path to the image file.
    Richiesto:
  • (array) $image_meta The attachment meta data array.
    Richiesto:
  • (int) $attachment_id Attachment Id to process.
    Richiesto:
Ritorna:
  • (array) The attachment metadata with updated `sizes` array. Includes an array of errors encountered while resizing.
Definito a:
Codex:

Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.

Intended for use after an image is uploaded. Saves/updates the image metadata after each sub-size is created. If there was an error, it is added to the returned image metadata array.



Sorgenti

function wp_create_image_subsizes( $file, $image_meta, $attachment_id ) {
	if ( empty( $image_meta ) || ! isset( $image_meta['width'], $image_meta['height'] ) ) {
		// New uploaded image.
		$imagesize            = getimagesize( $file );
		$image_meta['width']  = $imagesize[0];
		$image_meta['height'] = $imagesize[1];

		// Make the file path relative to the upload dir.
		$image_meta['file'] = _wp_relative_upload_path( $file );

		// Fetch additional metadata from EXIF/IPTC.
		$exif_meta = wp_read_image_metadata( $file );

		if ( $exif_meta ) {
			$image_meta['image_meta'] = $exif_meta;
		}
	}

	$new_sizes = wp_get_registered_image_subsizes();

	/**
	 * Filters the image sizes automatically generated when uploading an image.
	 *
	 * @since 2.9.0
	 * @since 4.4.0 Added the `$image_meta` argument.
	 * @since 5.3.0 Added the `$attachment_id` argument.
	 *
	 * @param array $new_sizes     Associative array of image sizes to be created.
	 * @param array $image_meta    The image meta data: width, height, file, sizes, etc.
	 * @param int   $attachment_id The attachment post ID for the image.
	 */
	$new_sizes = apply_filters( 'intermediate_image_sizes_advanced', $new_sizes, $image_meta, $attachment_id );

	return _wp_make_subsizes( $new_sizes, $file, $image_meta, $attachment_id );
}