当前位置: 动力学知识库 > 问答 > 编程问答 >

image - using get_serving_url() to resize SMALLER dimension (width or height) to a specific integer

问题描述:

I'm trying to use get_serving_url() to serve up thumbnails, but I need those those thumbnails' smaller dimension (could be width OR height) to be a certain number so that there won't be any gaps in its container div. According to the docs, the "size" argument for get_serving_url will adjust the LONGEST dimension to a given parameter. This might cause the opposite dimension to go below my required size. How can I fix this?

网友答案:

If you have the dimensions of the bitmap you can request a size that is larger than your smallest value by the factor of the image aspect ratio.
For example if the image is 1600x1200 and you want the thumbnail to be at least 32 pixels in in dimension, the size should be 43 (32*(1600/1200)) and the resulting image will be 43x32.

In order to get the image size you need to load the image date into the image class and use the width and height properties.

网友答案:

There's no way to do this currently; you will have to fetch the dimensions of the image and calculate the size of the longer size accordingly. You probably should do this anyway, or a 1x1000 image will break things for everyone.

分享给朋友:
您可能感兴趣的文章:
随机阅读: