diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php index e800aa7721452430160d35bf2bc4ca66d78e7686..b9a99b00a7a502063cf4aa538ae8b37d1d6e6a5e 100644 --- a/ecrire/inc/filtres.php +++ b/ecrire/inc/filtres.php @@ -21,6 +21,7 @@ include_spip('inc/charsets'); $GLOBALS['spip_matrice']['image_valeurs_trans'] = ''; $GLOBALS['spip_matrice']['image_reduire'] = ''; $GLOBALS['spip_matrice']['image_reduire_par'] = ''; +$GLOBALS['spip_matrice']['image_recadre'] = ''; $GLOBALS['spip_matrice']['image_alpha'] = ''; $GLOBALS['spip_matrice']['image_flip_vertical'] = ''; $GLOBALS['spip_matrice']['image_flip_horizontal'] = ''; diff --git a/ecrire/inc/filtres_images.php b/ecrire/inc/filtres_images.php index 7bd4046d1a74fd3c5154927312057c08c7f78e67..2c9dd72290232bcf4927d75f927ca75a558ca900 100644 --- a/ecrire/inc/filtres_images.php +++ b/ecrire/inc/filtres_images.php @@ -171,6 +171,63 @@ function image_alpha($im, $alpha = 63) return "<img src='$dest'$tags />"; } +function image_recadre($im,$width,$height,$position='center') +{ + $image = image_valeurs_trans($im, "recadre-$width-$height-$position"); + if (!$image) return(""); + + $x_i = $image["largeur"]; + $y_i = $image["hauteur"]; + + if ($width==0 OR $width>$x_i) $width==$x_i; + if ($height==0 OR $height>$y_i) $height==$y_i; + + $offset_width = $x_i-$width; + $offset_height = $y_i-$height; + $position=strtolower($position); + if (strpos($position,'left')!==FALSE) + $offset_width=0; + elseif (strpos($position,'right')!==FALSE) + $offset_width=$offset_width; + else + $offset_width=intval(ceil($offset_width/2)); + + if (strpos($position,'top')!==FALSE) + $offset_height=0; + elseif (strpos($position,'bottom')!==FALSE) + $offset_height=$offset_height; + else + $offset_height=intval(ceil($offset_height/2)); + + $im = $image["fichier"]; + $dest = $image["fichier_dest"]; + + $creer = $image["creer"]; + + if ($creer) { + $im = $image["fonction_imagecreatefrom"]($im); + $im_ = imagecreatetruecolor($width, $height); + @imagealphablending($im_, false); + @imagesavealpha($im_,true); + + $color_t = ImageColorAllocateAlpha( $im_, 255, 255, 255 , 127 ); + imagefill ($im_, 0, 0, $color_t); + imagecopy($im_, $im, 0, 0, $offset_width, $offset_height, $width, $height); + + $image["fonction_image"]($im_, "$dest"); + imagedestroy($im_); + imagedestroy($im); + } + + $class = $image["class"]; + if (strlen($class) > 1) $tags=" class='$class'"; + $tags = "$tags alt='".$image["alt"]."'"; + $style = $image["style"]; + if (strlen($style) > 1) $tags="$tags style='$style'"; + + return "<img src='$dest'$tags />"; +} + // http://doc.spip.org/@image_flip_vertical function image_flip_vertical($im) {