image_resize()

最后更新于:2021-11-27 06:40:16

image_resize( string$file, int$max_w, int$max_h, bool$crop=false, string$suffix=null, string$dest_path=null, int$jpeg_quality=90)

Scale down an image to fit a particular size and save a new copy of the image.

参数

$file

(string) (Required) Image file path.

$max_w

(int) (Required) Maximum width to resize to.

$max_h

(int) (Required) Maximum height to resize to.

$crop

(bool) (Optional) Whether to crop image or resize.

Default value: false

$suffix

(string) (Optional) File suffix.

Default value: null

$dest_path

(string) (Optional) New image file path.

Default value: null

$jpeg_quality

(int) (Optional) Image quality percentage.

Default value: 90

响应

(mixed) GC_Error on failure. String with new destination path.

源文件

文件: gc-includes/deprecated.php

function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 90 ) {
	_deprecated_function( __FUNCTION__, '3.5.0', 'gc_get_image_editor()' );

	$editor = gc_get_image_editor( $file );
	if ( is_gc_error( $editor ) )
		return $editor;
	$editor->set_quality( $jpeg_quality );

	$resized = $editor->resize( $max_w, $max_h, $crop );
	if ( is_gc_error( $resized ) )
		return $resized;

	$dest_file = $editor->generate_filename( $suffix, $dest_path );
	$saved = $editor->save( $dest_file );

	if ( is_gc_error( $saved ) )
		return $saved;

	return $dest_file;
}