image_resize()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
image_resize( string $file, int $max_w, int $max_h, bool $crop = false, string $suffix = null, string $dest_path = null, int $jpeg_quality = 90 ): mixed
Описание
Функция сохраняет прозрачность PNG, а также тип изображения. Если на входе файл PNG, то изменённое по размеру изображение тоже будет PNG. Поддерживаются только типы изображений PNG, GIF и JPEG.
Некоторые возможности требуют наличия соответствующего API, поэтому в некоторых версиях PHP поддержка может отсутствовать. Это не вина WordPress (где происходит понижение функциональности, а не реальные дефекты), а особенность вашей версии PHP.
См. alsowp_get_image_editor()
Оригинал (английский)
The PNG transparency will be preserved using the function, as well as the image type. If the file going in is PNG, then the resized image is going to be PNG. The only supported image types are PNG, GIF, and JPEG.
Some functionality requires API to exist, so some PHP version may lose out support. This is not the fault of WordPress (where functionality is downgraded, not actual defects), but of your PHP version.
Параметры
$file
string
обязательный
$max_w
int
обязательный
$max_h
int
обязательный
$crop
bool
необязательный
= false
$suffix
string
необязательный
= null
$dest_path
string
необязательный
= null
$jpeg_quality
int
необязательный
= 90
Возвращаемое значение
mixed
Исходный код
wp-includes/deprecated.php:3253
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
_deprecated_function( __FUNCTION__, '3.5.0', 'wp_get_image_editor()' );
$editor = wp_get_image_editor( $file );
if ( is_wp_error( $editor ) )
return $editor;
$editor->set_quality( $jpeg_quality );
$resized = $editor->resize( $max_w, $max_h, $crop );
if ( is_wp_error( $resized ) )
return $resized;
$dest_file = $editor->generate_filename( $suffix, $dest_path );
$saved = $editor->save( $dest_file );
if ( is_wp_error( $saved ) )
return $saved;
return $dest_file;
}
История изменений
| Версия | Описание |
|---|---|
| 3.5.0 | Deprecated. Use wp_get_image_editor() |
| 2.5.0 | Introduced. |

