My client ask for a page where I crop the thumbnail to be square evenly cropped from top, bottom ,left and right.
here's my code :
The crop is working but not centered. You can view the result on this page : http://irenefw.com/fr/portfolio.php?categorie=1
Any suggestion will be welcomed.
here's my code :
Code:
<?php
$sql_diapo=mysql_query("SELECT * FROM diapo WHERE categorie = '".$_GET['categorie']."' ORDER BY ordre ASC");
while($ligne_diapo=mysql_fetch_array($sql_diapo)){
// ================ CALCULER HAUTEUT ET LARGEUR ================
$laphoto="http://irenefw.com/media/photo/petit/".$ligne_diapo['id_diapo'].".jpg ";
$laphoto_g="http://irenefw.com/media/photo/grand/".$ligne_diapo['id_diapo'].".jpg ";
list($width, $height) = getimagesize($laphoto);
if($width > $height){ // paysage
$trop_large = $width - $height; //largeur moins hauteur
$coupe_large=$trop_large / 2; //resultat divisé par 2 (gauche-droite)
$largeur=$coupe_large / $width * 100; // en pourcentage
$largeur2=ceil($largeur); // arrondi
}
else{ // portrait
$trop_haut = $height - $width; //hauteur moins largeur
$coupe_haut=$trop_haut / 2; //resultat divisé par 2 (haut-bas)
$hauteur=$coupe_haut / $height *100; // en pourcentage
$hauteur2=ceil($hauteur); // arrondi à l'entier supérieur
}
echo "<div class=diapo>L:".$largeur2." H:".$hauteur2."<br><div style=' ";
if (isset($largeur2)){ echo "left: -".$largeur2."%;"; echo "right: -".$largeur2."%;";}
if (isset($hauteur2)){ echo " top: -".$hauteur2."%;"; echo " bottom: -".$hauteur2."%;";}
echo " '><a class=fancybox href=".$laphoto_g." data-fancybox-group=".$_GET['categorie']." title='".$ligne_diapo['legende']."'><img src=".$laphoto."></a></div></div>";
}
?>
The crop is working but not centered. You can view the result on this page : http://irenefw.com/fr/portfolio.php?categorie=1
Any suggestion will be welcomed.