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.