PHP

HOW TO RESIZE IMAGES IN PHP

READ THE ORIGINAL IMAGE $original = imagecreatefromjpeg ("IMAGE.jpg");   ORIGINAL IMAGE SIZE $dim = getimagesize($original); $ow = $dim[0]; $oh = $dim[1];

OPEN ORIGINAL IMAGE

01

CREATE NEW CANVAS

02

RESIZED DIMENSIONS (50% ORIGINAL) $rw = ceil(0.5 * $ow); $rh = ceil(0.5 * $oh); EMPTY CANVAS $resized = imagecreatetruecolor ($rw, $rh); 

RESIZE IMAGE $tx = 0; $ty = 0; $sx = 0; $sy = 0;   imagecopyresampled($resized, $original, $tx, $ty, $sx, $sy, $rw, $rh, $ow, $oh);

RESIZE & SAVE IMAGE

03

SAVE RESIZED IMAGE imagejpeg($resized, "resized.jpg");