How do I resize and convert an uploaded image to a PNG using GD?

前端 未结 9 1399
离开以前
离开以前 2020-12-05 16:08

I want to allow users to upload avatar-type images in a variety of formats (GIF, JPEG, and PNG at least), but to save them all as PNG database BLOBs

9条回答
  •  暖寄归人
    2020-12-05 16:49

    Your process steps should look like this:

    1. Verify the filetype
    2. Load the image if it is a supported filetype into GD using imagecreatefrom*
    3. Resizing using imagecopyresize or imagecopyresampled
    4. Save the image using imagepng($handle, 'filename.png', $quality, $filters)

    ImageMagick is faster, generates better images, is more configurable, and finally is (IMO) much easier to code for.

    @ceejayoz Just wait for the new GD - it's OOP like MySQLi and it's actually not bad :)

提交回复
热议问题