PHP GD - resizing image frame / canvas, but not the actual image

I have an image of 88x31 size and you want to make it 100x100 without resizing the image, but only its canvas / frame, possibly copying it in the center of a new pure white image with a size of 100x100. Any ideas how to do this?

+6
source share
2 answers

You can see it here: Sketching using a PHP tutorial

+6
source

The correct method is to create a new image and then copy the old image to the middle (provided that the initial image is JPEG and less than 100x100):

$oldimage = imagecreatefromjpeg($filename); $oldw = imagesx($oldimage); $oldh = imagesy($oldimage); $newimage = imagecreatetruecolor(100, 100); // Creates a black image // Fill it with white (optional) $white = imagecolorallocate($newimage, 255, 255, 255); imagefill($newimage, 0, 0, $white); imagecopy($newimage, $oldimage, (100-$oldw)/2, (100-$oldh)/2, 0, 0, $old, $oldh); 
+7
source

Source: https://habr.com/ru/post/905291/


All Articles