Resize/crop/pad a picture to a fixed size

前端 未结 11 1794
孤城傲影
孤城傲影 2020-11-27 14:58

I need to resize a picture to a fixed size. But it has to keep the factors between the width and height.

Say I want to resize a picture from 238 (w) X 182 (

11条回答
  •  半阙折子戏
    2020-11-27 15:48

    The technique is to:

    1. resize the image so that one dimension matches while the other exceeds the desired dimensions
    2. take out the desired size image from the center of resized image.

    Lastly if you are puzzled about how to do the resize math, remember that if proportions of source and destination images are same, this relation holds:

    SourceWidth / SourceHeight = DestinationWidth / DestinationHeight
    

    If you know three parameters, you can calculate the fourth one easily.

    I wrote an article about this:
    Crop-To-Fit an Image Using ASP/PHP

提交回复
热议问题