-1

my current project involves getting all uploaded images to the same size in the end. Furthermore I would like to hear about your approaches on how to do the image manipulation.

What I want to do: A user uploads an image with the size of 2560x1440. Now I want to display the image with the size of 1280x720. Well that's the easy part. Every library can scale an image down like that. But if a user uploads an image with like 500x2000 a rescale to 1280x720 will be very ugly. My idea was to create a blank image with the size of 1280x720 and scale the incoming image down to a heigt of 720 and make the background in gray. If you can follow me so far, the new image will now be 1280x720 but on the side it's filled gray with the original image in the center.enter image description here

Would you do this the same way? Is there a library out there, that is capable of this?

Thank ahead DaNeubi

DaNeubi
  • 93
  • 11

1 Answers1

2

Sounds like a reasonable approach. I'd look at ImageMagick for which there is a PHP extension. You'll need to write the logic to determine the image rescaling and background sizing.

Tom
  • 880
  • 6
  • 17
  • 2
    ImageMagick is *the* first library to look at for PHP image manipulation. The OP needs to look at 1) resizing (as stated), 2) cropping and 3) composite. At a minimum, he'll need all three operations for this use case, – paulsm4 Dec 25 '21 at 22:05
  • Thanks for your idea. So ImageMagick it is. – DaNeubi Dec 26 '21 at 13:05