To scale images up, we use the same approach as in resizing images.
<?php
$file = '/var/www/examples/small.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);
$imf = imagecreatetruecolor($size[0]*10,$size[1]*10);
imagealphablending($imf, false);
imagesavealpha($imf, true);
imagecopyresampled($imf, $im, 0,0,0,0, $size[0]*10,$size[1]*10,$size[0],$size[1]);
imagePng($imf, '/tmp/image.png');
/var/www/examples/small.png
- path to image to scale upgetimagesize
- returns image size from given pathimagecreatefrompng
- creates lib:GD image object from given PNG imageimagecreatetruecolor
- creates true color lib:GD image object with specified width & heightimagealphablending
- we're disabling alpha blending to prevent transparent background being converted to black colorimagesavealpha
- we're enabling alpha channel (controls transparency) for resulting imageimagecopyresampled
- resizes source image and writes result to destination imageimagePng
- saves image in PNG format to the given path
group: resize
<?php
$file = '/var/www/examples/small.png';
$size = getimagesize($file);
$im = imagecreatefrompng($file);
$imf = imagecreatetruecolor($size[0]*10,$size[1]*10);
imagealphablending($imf, false);
imagesavealpha($imf, true);
imagecopyresampled($imf, $im, 0,0,0,0, $size[0]*10,$size[1]*10,$size[0],$size[1]);
imagePng($imf, '/tmp/image.png');