您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

调整和裁剪缩略图图像Resize and crop thumbnail images

警告

必应搜索 API 将从认知服务迁移到必应搜索服务。Bing Search APIs are moving from Cognitive Services to Bing Search Services. 2020 年10月 30 日起,需要按照 此处所述的过程设置必应搜索的任何新实例。Starting October 30, 2020 , any new instances of Bing Search need to be provisioned following the process documented here. 在接下来的三年中,将支持使用认知服务进行预配的必应搜索 API,或者在企业协议结束后(以先发生者为准)。Bing Search APIs provisioned using Cognitive Services will be supported for the next three years or until the end of your Enterprise Agreement, whichever happens first. 有关迁移说明,请参阅 必应搜索服务For migration instructions, see Bing Search Services.

必应搜索 API 中的某些解答包括 Bing 提供的缩略图图像的 Url,可以调整大小和进行裁剪,还可以包含查询参数。Some answers from the Bing Search APIs include URLs to thumbnail images served by Bing, which you can resize and crop, and may contain query parameters. 例如:For example:

https://<host>/th?id=AMMS_92772df988...&w=110&h=73&rs=1&qlt=80&cdv=1&pid=16.1

如果显示这些缩略图的一个子集,请提供一个选项以查看剩余图像。If you display a subset of these thumbnails, provide an option to view the remaining images.

备注

请确保裁剪和调整缩略图的大小会根据必应搜索 API 使用和显示要求所要求的那样,提供遵循第三方权限的搜索方案。Be sure that cropping and resizing thumbnail images will provide a search scenario that respects third party rights, as required by the Bing Search API use and display requirements.

调整缩略图的大小Resize a thumbnail

若要调整缩略图的大小,必应建议仅在 w h 缩略图的 URL 中指定 (宽度) 或 (高度) 查询参数。To resize a thumbnail, Bing recommends that you specify only one the w (width) or h (height) query parameters in the thumbnail's URL. 仅指定高度或宽度后,必应保持图像的原始方位。Specifying only the height or width lets Bing maintain the image's original aspect. 以像素为单位指定宽和高。Specify the width and height in pixels.

例如,如果原始缩略图为480x620:For example, if the original thumbnail is 480x620:

https://<host>/th?id=JN.5l3yzwy%2f%2fHj59U6XhssIQ&pid=Api&w=480&h=620

要减小其大小,请将 w 参数设置为新值 (例如 336) ,并删除 h 参数:And you want to decrease its size, set the w parameter to a new value (for example 336), and remove the h parameter:

https://<host>/th?id=JN.5l3yzwy%2f%2fHj59U6XhssIQ&pid=Api&w=336

如果仅指定缩略图的高度或宽度,则将保留图像的原始纵横比。If you specify only the height or width of a thumbnail, the image's original aspect ratio will be maintained. 如果同时指定了这两个参数,并且不保留纵横比,必应将空白边距添加到图像的边框。If you specify both parameters, and the aspect ratio isn't maintained, Bing will add white padding to the border of the image.

例如,如果在不进行裁剪的情况下将480x359 图像调整为200x200 大小,则完整宽度将包含图像,但高度将包含25个像素的空白,位于图像的顶部和底部。For example, if you resize a 480x359 image to 200x200 without cropping, the full width will contain the image but the height will contain 25 pixels of white padding at the top and bottom of the image. 如果图像是359x480,则左边框和右边框将包含白色填充。If the image was 359x480, the left and right borders would contain white padding. 如果裁剪图像,不会添加白色填充内容。If you crop the image, white padding is not added.

下图显示缩略图的原始大小 (480x300)。The following picture shows the original size of a thumbnail image (480x300).

原始风景图

下图显示调整为 200x200 大小后的图像。The following picture shows the image resized to 200x200. 保持纵横比,并将上边框和下边框填充为白色 (其中包含的黑色边框用于显示边距) 。The aspect ratio is maintained and the top and bottom borders are padded with white (the black border here is included to show the padding).

调整大小后的风景图

如果指定的尺寸大于图像的原始宽度和高度,必应将空白边距添加到左边框和上边框。If you specify dimensions that are greater than the image’s original width and height, Bing will add white padding to the left and top borders.

请求不同的缩略图大小Request different thumbnail sizes

若要请求其他缩略图大小,请从缩略图的 URL 中删除所有查询参数( idpid 参数除外)。To request a different thumbnail image size, remove all query parameters from the thumbnail's URL, except the id and pid parameters. 然后 &w ,将 (width) 或 &h (高度) 查询参数添加所需的图像大小(以像素为单位),但不能同时添加两者。Then add either the &w (width) or &h (height) query parameter with the desired image size in pixels, but not both. 必应将保持图像的原始纵横比。Bing will maintain the image's original aspect ratio.

若要将上述 URL 指定的图像宽度增加到165像素,请使用以下 URL:To increase the width of the image specified by the above URL to 165 pixels, you would use the following URL:

https://<host>/th?id=AMMS_92772df988...&w=165&pid=16.1

如果请求的图像大于图像的原始大小,必应根据需要在图像周围添加白色空白。If you request an image that’s larger than the image’s original size, Bing adds white padding around the image as needed. 例如,如果图像的原始大小为474x316,并将设置 &w 为500,必应会返回500x333 图像。For example, if the image’s original size is 474x316 and you set &w to 500, Bing will return a 500x333 image. 此图像沿上边缘和下边缘均为8.5 像素的白色填充,左侧边缘和右边缘有13像素的空白。This image will have 8.5 pixels of white padding along the top and bottom edges, and 13 pixels of padding on the left and right edges.

若要防止必应在所请求的大小大于图像的原始大小时添加白色填充,请将 &p 查询参数设置为0。To prevent Bing from adding white padding if the requested size is greater than the image’s original size, set the &p query parameter to 0. 例如,如果在 &p=0 上述 URL 中包含参数,必应会返回474x316 图像而不是500x333 图像:For example, if you include the &p=0 parameter in the above URL, Bing will return a 474x316 image instead of a 500x333 image:

https://<host>/th?id=AMMS_92772df988...&w=500&p=0&pid=16.1

如果同时指定 &w&h 查询参数,必应会保持图像的纵横比,并根据需要添加空白。If you specify both &w and &h query parameters, Bing will maintain the image’s aspect ratio and adds white padding as needed. 例如,如果图像的原始大小为474x316,并将宽度和高度参数设置为200x200 大小 (&w=200&h=200) ,必应返回在顶部和底部包含33像素的空白的图像。For example, if the image’s original size is 474x316 and you set the width and height parameters to 200x200 (&w=200&h=200), Bing returns an image that contains 33 pixels of white padding on the top and bottom. 如果包括 &p 查询参数,必应返回200x134 图像。If you include the &p query parameter, Bing returns an 200x134 image.

裁剪缩略图Crop a thumbnail

若要裁剪图像,请包含 c (剪裁) query 参数。To crop an image, include the c (crop) query parameter. 可以使用下列值:You can use the following values:

  • 4—盲比4 — Blind Ratio
  • 7—智能比率7 — Smart Ratio

智能比率裁剪Smart Ratio cropping

如果通过将参数设置为 ") 请求智能比率裁剪 (c 7 ,必应会从其感兴趣的区域中心开始裁剪图像,同时保持图像的纵横比。If you request Smart Ratio cropping (by setting the c parameter to 7), Bing will crop an image from the center of its region of interest outward, while maintaining the image’s aspect ratio. 感兴趣区域是图像中被必应确定为包含最重要内容的区域。The region of interest is the area of the image that Bing determines contains the most import parts. 下图是感兴趣区域的示例。The following shows an example region of interest.

感兴趣区域

如果调整图像大小并请求智能比率裁剪,必应在保持纵横比的同时,将图像缩小到所请求的大小。If you resize an image and request Smart Ratio cropping, Bing reduces the image to the requested size while maintaining the aspect ratio. 然后,必应根据调整了大小的尺寸裁剪该图像。Bing then crops the image based on the resized dimensions. 例如,如果调整了大小的宽度小于或等于高度,必应会将图像裁剪到感兴趣的区域的左侧和右侧。For example, if the resized width is less than or equal to the height, Bing will crop the image to the left and right of the center of the region of interest. 否则,必应会将其裁剪到感兴趣的区域的顶部和底部。Otherwise, Bing will crop it to the top and bottom of the center of the region of interest.

下图显示使用“智能比例”裁剪将图像缩成 200x200 大小的情形。The following shows the image reduced to 200x200 using Smart Ratio cropping. 由于必应从左上角测量图像,因此会裁剪图像的下半部分。Because Bing measures the image from the top-left corner, the bottom part of the image is cropped.

裁剪成 200x200 大小的风景图

下图显示使用“智能比例”裁剪将图像缩成 200x100 大小的情形。The following shows the image reduced to 200x100 using Smart Ratio cropping. 由于必应从左上角测量图像,因此会裁剪图像的下半部分。Because Bing measures the image from the top-left corner, the bottom part of the image is cropped.

裁剪成 200x100 大小的风景图

下图显示使用“智能比例”裁剪将图像缩成 100x200 大小的情形。The following shows the image reduced to 100x200 using Smart Ratio cropping. 因为必应从中心测量图像,所以图像的左右部分会被裁剪。Because Bing measures the image from the center, the left and right parts of the image are cropped.

裁剪成 100x200 大小的风景图

如果 Bing 无法确定图像的感兴趣区域,则该服务将使用盲率裁剪。If Bing cannot determine the image’s region of interest, the service will use Blind Ratio cropping.

盲比值裁剪Blind Ratio cropping

如果通过将参数设置为 ") 请求 (盲比值裁剪 c 4 ,必应使用以下规则来裁剪该图像。If you request Blind Ratio cropping (by setting the c parameter to 4), Bing uses the following rules to crop the image.

  • 如果为 (Original Image Width / Original Image Height) < (Requested Image Width / Requested Image Height) ,则从左上角测量图像,并在底部进行裁剪。If (Original Image Width / Original Image Height) < (Requested Image Width / Requested Image Height), the image is measured from top-left corner and cropped at the bottom.
  • 如果为 (Original Image Width / Original Image Height) > (Requested Image Width / Requested Image Height) ,则图像从中心开始测量,并向左和向右裁剪。If (Original Image Width / Original Image Height) > (Requested Image Width / Requested Image Height), the image is measured from the center and cropped to the left and right.

下面是 225x300 大小的纵向图。The following shows a portrait image that’s 225x300.

原始向日葵图

下图显示使用“盲比例”裁剪将图像缩成 200x200 大小的情形。The following shows the image reduced to 200x200 using Blind Ratio cropping. 从左上角测量图像,导致裁剪图像底部的部分。The image is measured from the top-left corner resulting in the bottom part of the image being cropped.

裁剪成 200x200 大小的向日葵图

下图显示使用“盲比例”裁剪将图像缩成 200x100 大小的情形。The following shows the image reduced to 200x100 using Blind Ratio cropping. 从左上角测量图像,导致裁剪图像底部的部分。The image is measured from the top-left corner resulting in the bottom part of the image being cropped.

裁剪成 200x100 大小的向日葵图

下图显示使用“盲比例”裁剪将图像缩成 100x200 大小的情形。The following shows the image reduced to 100x200 using Blind Ratio cropping. 图像从中心进行测量,因此会裁剪其左侧和右侧。The image is measured from the center resulting in the left and right parts of the image being cropped.

裁剪成 100x200 大小的向日葵图

后续步骤Next steps