Algorithm to resize image and maintain aspect ratio to fit iPhone

后端 未结 5 843
傲寒
傲寒 2020-12-24 04:55

I\'m creating a web service for an iPhone app to interact with.

When my client uploads images server-side, I want my php script to resize the image, whilst m

5条回答
  •  天命终不由人
    2020-12-24 05:54

    Any one coming to this page from Google looking for ASPECT FILL not ASPECT FIT, it is simply a matter of switching the ratio selection code i.e:

    Jim's answer:

    resizeRatio = Min(wRatio, hRatio); //Aspect Fit
    

    becomes

    resizeRatio = Max(wRatio, hRatio); //Aspect Fill
    

    DevProd's answer:

    float ratio = ratioW < ratioH?ratioW:ratioH; //Aspect Fit
    

    becomes

    float ratio = ratioW > ratioH?ratioW:ratioH; //Aspect Fill
    

提交回复
热议问题