Bonjour, j'ai enfin récemment évoluer sur mon code.
Mais je bloque sur le stade final de mon projet où je voudrais afficher mes PNG côte à côte sur mon sprite.
Voici mon code:
<?php
function getImages($path)
{
$dh = opendir($path);
$t_width = array();
$t_height = array();
$myImages = array();
while (false !== ($files = readdir($dh))) {
if ($files != "." && $files != "..") {
list($width, $height) = getimagesize($path . "/" . $files);
$t_width[] = $width;
$t_height[] = $height;
$img = imagecreatefrompng($path . "/" . $files);
array_push($myImages, $img);
}
}
$n_width = array_sum($t_width);
$n_height = max($t_height);
$all_img = imagecreatetruecolor($n_width, $n_height);
$background = imagecolorallocatealpha($all_img, 255, 255, 255, 127);
imagefill($all_img, 0, 0, $background);
imagealphablending($all_img, false);
imagesavealpha($all_img, true);
$pos_x = 0;
$pos_y = 0;
for ($i = 0; $i < count($myImages); $i++) {
$myImages[$i];
$t_width[$i];
$n_width = $t_width[$i];
imagecopy($all_img, $img, $pos_x, $pos_y, 0, 0, $n_width, $n_height);
}
$sprite = "sprite.png";
imagepng($all_img, $sprite);
}
getImages("images");
Je sais que le problème provient du côté de mon "for" , étant débutant je tourne en rond pour trouver la solution...
J'ai réussi à créer un sprite, qui affiche une seule png pour le moment au lieu de toutes les afficher.
On m'a dit que ce serait un problème de positionnement de mes png .
Le résultat visuel : impossible de montrer une image externe.