PHP Scale image and then create image of specific size

Posted by Ronny vdb on Stack Overflow See other posts from Stack Overflow or by Ronny vdb
Published on 2013-11-02T21:50:01Z Indexed on 2013/11/02 21:53 UTC
Read the original article Hit count: 256

Filed under:
|

The result I am trying to achieve is that the user can upload an image of any size, and the server side script will convert it to an image that has the dimension 1024x512.

To save the aspect ratio of the image I first scale the image down by either the width or height to match the wanted dimensions.

to do this I am using imagecopyresampled():

imagecopyresampled(
        $new_img,
        $src_img,
        $dst_x,
        $dst_y,
        0,
        0,
        $new_width,
        $new_height,
        $img_width,
        $img_height
    ) && $write_image($new_img, $new_file_path, $image_quality);

If we take an image that is 1920x1200 as an example, the outputted image will be 819x512. However I still need a final result of 1024x512 so I want to add white borders to the image to will the width to 1024.

How can I correct my imagecopyresampled function to acheive this?

© Stack Overflow or respective owner

Related posts about php

Related posts about image