0
I need to resize all images when sharing on Facebook. There are several images of various sizes in the product listing, but when I share the link on Facebook, depending on the size of the image, Facebook put in the larger picture box or smaller box, depending on the size. What I need to do, is to play to the meta OG the image with the size changed.
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.
Follows 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 image readjusted in the meta og.