Skip to content
Extraits de code Groupes Projets
Valider 1e22452f rédigé par cedric@yterium.com's avatar cedric@yterium.com
Parcourir les fichiers

Quand on aplatit une image qui est déjà un JPG (pour utiliser une compression...

Quand on aplatit une image qui est déjà un JPG (pour utiliser une compression plus forte par exemple), inutile de recopier les px un par un car il n'y a pas de transparence
(fil)
parent 46a860e8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -88,44 +88,51 @@ function image_aplatir($im, $format='jpg', $coul='000000', $qualite=NULL, $trans ...@@ -88,44 +88,51 @@ function image_aplatir($im, $format='jpg', $coul='000000', $qualite=NULL, $trans
$transp_x = false; $transp_x = false;
for ($x = 0; $x < $x_i; $x++) { if ($image["format_source"] == "jpg") {
for ($y=0; $y < $y_i; $y++) { $im_ = &$im;
}
$rgb = ImageColorAt($im, $x, $y); else {
$a = ($rgb >> 24) & 0xFF; for ($x = 0; $x < $x_i; $x++) {
$r = ($rgb >> 16) & 0xFF; for ($y=0; $y < $y_i; $y++) {
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
$a = (127-$a) / 127; $rgb = ImageColorAt($im, $x, $y);
$a = ($rgb >> 24) & 0xFF;
if ($a == 1) { // Limiter calculs $r = ($rgb >> 16) & 0xFF;
$r = $r; $g = ($rgb >> 8) & 0xFF;
$g = $g; $b = $rgb & 0xFF;
$b = $b;
} $a = (127-$a) / 127;
else if ($a == 0) { // Limiter calculs
$r = $dr; if ($a == 1) { // Limiter calculs
$g = $dv; $r = $r;
$b = $db; $g = $g;
$b = $b;
$transp_x = $x; // Memoriser un point transparent }
$transp_y = $y; else if ($a == 0) { // Limiter calculs
$r = $dr;
} else { $g = $dv;
$r = round($a * $r + $dr * (1-$a)); $b = $db;
$g = round($a * $g + $dv * (1-$a));
$b = round($a * $b + $db * (1-$a)); $transp_x = $x; // Memoriser un point transparent
$transp_y = $y;
} else {
$r = round($a * $r + $dr * (1-$a));
$g = round($a * $g + $dv * (1-$a));
$b = round($a * $b + $db * (1-$a));
}
$a = (1-$a) *127;
$color = ImageColorAllocateAlpha( $im_, $r, $g, $b, $a);
imagesetpixel ($im_, $x, $y, $color);
} }
$a = (1-$a) *127;
$color = ImageColorAllocateAlpha( $im_, $r, $g, $b, $a);
imagesetpixel ($im_, $x, $y, $color);
} }
} }
// passer en palette si besoin // passer en palette si besoin
if ($format=='gif' OR ($format=='png' AND $qualite!==0)){ if ($format=='gif' OR ($format=='png' AND $qualite!==0)){
// creer l'image finale a palette (on recycle l'image initiale) // creer l'image finale a palette
// (on recycle l'image initiale si possible, sinon on en recree une)
if ($im===$im_)
$im = imagecreatetruecolor($x_i, $y_i);
@imagetruecolortopalette($im,true,$qualite); @imagetruecolortopalette($im,true,$qualite);
...@@ -149,8 +156,9 @@ function image_aplatir($im, $format='jpg', $coul='000000', $qualite=NULL, $trans ...@@ -149,8 +156,9 @@ function image_aplatir($im, $format='jpg', $coul='000000', $qualite=NULL, $trans
} }
else else
_image_gd_output($im_, $image, $qualite); _image_gd_output($im_, $image, $qualite);
if ($im!==$im_)
imagedestroy($im);
imagedestroy($im_); imagedestroy($im_);
imagedestroy($im);
} }
return _image_ecrire_tag($image,array('src'=>$dest)); return _image_ecrire_tag($image,array('src'=>$dest));
} }
......
<paquet <paquet
prefix="images" prefix="images"
categorie="multimedia" categorie="multimedia"
version="1.1.7" version="1.1.8"
etat="stable" etat="stable"
compatibilite="[3.0.0;3.1.*]" compatibilite="[3.0.0;3.1.*]"
logo="images/image_filtre-32.png" logo="images/image_filtre-32.png"
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter