WP_Image_Editor_Imagick::_save()protectedWP 3.5.0

Метод класса: WP_Image_Editor_Imagick{}

Хуки из метода

Возвращает

Массив|WP_Error. Array on success or WP_Error if the file failed to save.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->_save( $image, $filename, $mime_type );
$image(Imagick) (обязательный)
-
$filename(строка)
-
По умолчанию: null
$mime_type(строка)
-
По умолчанию: null

Список изменений

С версии 3.5.0 Введена.
С версии 6.0.0 The $filesize value was added to the returned array.

Код WP_Image_Editor_Imagick::_save() WP 6.4.3

protected function _save( $image, $filename = null, $mime_type = null ) {
	list( $filename, $extension, $mime_type ) = $this->get_output_format( $filename, $mime_type );

	if ( ! $filename ) {
		$filename = $this->generate_filename( null, null, $extension );
	}

	try {
		// Store initial format.
		$orig_format = $this->image->getImageFormat();

		$this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) );
	} catch ( Exception $e ) {
		return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
	}

	$write_image_result = $this->write_image( $this->image, $filename );
	if ( is_wp_error( $write_image_result ) ) {
		return $write_image_result;
	}

	try {
		// Reset original format.
		$this->image->setImageFormat( $orig_format );
	} catch ( Exception $e ) {
		return new WP_Error( 'image_save_error', $e->getMessage(), $filename );
	}

	// Set correct file permissions.
	$stat  = stat( dirname( $filename ) );
	$perms = $stat['mode'] & 0000666; // Same permissions as parent folder, strip off the executable bits.
	chmod( $filename, $perms );

	return array(
		'path'      => $filename,
		/** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
		'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
		'width'     => $this->size['width'],
		'height'    => $this->size['height'],
		'mime-type' => $mime_type,
		'filesize'  => wp_filesize( $filename ),
	);
}