Resize in image with PHP

1

I need to resize all images when sharing on Facebook. There are several images of various sizes in the product listing, however when I share the link on Facebook, depending on the size of the image, Facebook put in the bigger picture box or smaller box depending on the size. What I need to do, is to play to the OG target the image with the changed size.

I found a function that gives resize, but it gives in percentage and I need the image to be readjusted to the exact size of 600x315px.

Follow the code:

<?php
// Imagem e novo tamanho (em porcentagem)
$filename = '1.jpg';
$percent = 0.5;

// Content type
header('Content-Type: image/jpeg');

list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

imagejpeg($thumb);

?>
<meta property="og:image" content=""/>

After this, I need to play the readjusted image in the og goal.

    
asked by anonymous 04.01.2017 / 14:52

1 answer

3

Instead of using:

$newwidth = $width * $percent;
$newheight = $height * $percent;

Switch to:

$newwidth = 600;
$newheight = 315;

But the images will be stretched.

To put in your facebook goal:

<meta property="og:image" content="http://www.urldoseusite.com.br/pasta/onde/ficam/suas/imagens/<?php echo $filename; ?>"/>
    
04.01.2017 / 15:08