How to set default size of a PHP image

3

I would like to know if there is any way to set the height, and the default width in php, I saw some forms, but I used an external class, I wonder if there is any way to use the GD library ...

$dest = imagecreatefromjpeg('imgs/bg.jpg');
$tamanho = imagesx($dest);
$width = 594;
$height = 387;

$src = imagecreatefrompng('imgs/textura.png');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, -30, -50, 0, 0, 700, 500, 50); 
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
    
asked by anonymous 16.11.2015 / 00:42

1 answer

1

What you want can be solved this way:

$dest = imagecreatefromjpeg('imgs/bg.jpg');
$tamanho = imagesx($dest);
$width = 594;
$height = 387;

$larguraPadrao = 700;
$alturaPadrao  = 500;

$centro_x      = ceil( ( $larguraPadrao-$width ) / 2 );
$centro_y      = ceil( ( $alturaPadrao-$height ) / 2 );

$src = imagecreatefrompng('imgs/textura.png');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, $centro_x, $centro_y, 0, 0, $larguraPadrao, $alturaPadrao, 50);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
    
18.11.2015 / 19:14