我认为你很好,但你不需要使用其他功能。你有全部
File: wp-includes/media.php
例如,您可以
_wp_get_image_size_from_meta
要获取图像尺寸,无需使用以下内容:
$size = getimagesize($file);
$width = $size[0];
$height = $size[1];
$mime = $size[\'mime\'];
获取图像尺寸和类型。
另一方面,不清楚为什么不使用add_image_size
File: wp-includes/media.php
256: /**
257: * Register a new image size.
258: *
259: * Cropping behavior for the image size is dependent on the value of $crop:
260: * 1. If false (default), images will be scaled, not cropped.
261: * 2. If an array in the form of array( x_crop_position, y_crop_position ):
262: * - x_crop_position accepts \'left\' \'center\', or \'right\'.
263: * - y_crop_position accepts \'top\', \'center\', or \'bottom\'.
264: * Images will be cropped to the specified dimensions within the defined crop area.
265: * 3. If true, images will be cropped to the specified dimensions using center positions.
266: *
267: * @since 2.9.0
268: *
269: * @global array $_wp_additional_image_sizes Associative array of additional image sizes.
270: *
271: * @param string $name Image size identifier.
272: * @param int $width Image width in pixels.
273: * @param int $height Image height in pixels.
274: * @param bool|array $crop Optional. Whether to crop images to specified width and height or resize.
275: * An array can specify positioning of the crop area. Default false.
276: */
277: function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
278: global $_wp_additional_image_sizes;
279:
280: $_wp_additional_image_sizes[ $name ] = array(
281: \'width\' => absint( $width ),
282: \'height\' => absint( $height ),
283: \'crop\' => $crop,
284: );
285: }
您可以设置
$crop
选项设置为true,并创建16:9比例的缩略图。这会将图像组织到特定的大小。
您可以多次添加:
add_image_size( \'andy1\', 160, 90 , true);
add_image_size( \'andy2\', 1600, 900, true);
如果可能的话,将以您喜欢的方式创建缩略图。
如果您与image srcset
属性这很方便。