From 24192b205dd81d8d83c5ec80205271634a75efbf Mon Sep 17 00:00:00 2001
From: Cerdic <cedric@yterium.com>
Date: Fri, 13 Oct 2006 20:48:19 +0000
Subject: [PATCH] "#URL_DOCUMENT|image_recadre{largeur,hauteur,alignement}
 alignement est pas defaut 'center' si non precise, et prend les valeurs
 left,right,center,top,bottom par exemple
 #URL_DOCUMENT|image_recadre{150,150,'top left'} recadrera un carre de 150px
 dans le coin superieur gauche de l'image d'origine"

---
 ecrire/inc/filtres.php        |  1 +
 ecrire/inc/filtres_images.php | 57 +++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/ecrire/inc/filtres.php b/ecrire/inc/filtres.php
index e800aa7721..b9a99b00a7 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 7bd4046d1a..2c9dd72290 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)
 {
-- 
GitLab