Changeset 93465 in spip-zone
- Timestamp:
- Dec 8, 2015, 10:44:09 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
_core_/plugins/filtres_images/filtres/images_transforme.php
r93092 r93465 236 236 imagedestroy($im2); 237 237 } 238 239 238 240 239 return _image_ecrire_tag($image,array('src'=>$dest)); 241 242 240 } 243 241 244 242 /** 243 * Recadre (rogne) une image en indiquant la taille de la découpe souhaitée 245 244 * 246 * http://code.spip.net/@image_recadre 245 * On peut indiquer une proportion ou une taille spécifique, une position de rognage 246 * et une couleur de fond, si le rognage est de taille plus grande que l'image d'origine. 247 247 * 248 * @example 249 * - `[(#FICHIER|image_recadre{800, 400})]` 250 * - `[(#FICHIER|image_recadre{800, 400, center})]` 251 * - `[(#FICHIER|image_recadre{800, 400, center, black})]` 252 * - `[(#FICHIER|image_recadre{16:9})]` 253 * - `[(#FICHIER|image_recadre{16:9, -})]` (- est appliqué par défaut, équivalent à image_passe_partout) 254 * - `[(#FICHIER|image_recadre{16:9, +, center, white})]` 255 * - `[(#FICHIER|image_recadre{16:9, -, top left})]` 256 * - `[(#FICHIER|image_recadre{16:9, -, top=40 left=20})]` 257 * 258 * @filtre 259 * @uses _image_valeurs_trans() 260 * @uses _image_tag_changer_taille() si image trop grande pour être traitée 261 * @uses _image_ecrire_tag() 262 * @link http://www.spip.net/5786 263 * 248 264 * @param string $im 265 * Chemin de l'image ou balise html `<img src=... />` 249 266 * @param string|int $width 250 * largeur du recadrage251 * ou ratio sous la forme "16:9"267 * Largeur du recadrage 268 * ou ratio sous la forme "16:9" 252 269 * @param string|int $height 253 * hauteur du recadrage254 * ou "+" (agrandir) ou "-" (reduire) si un ratio est fourni pour width270 * Hauteur du recadrage 271 * ou "+" (agrandir) ou "-" (reduire) si un ratio est fourni pour width 255 272 * @param string $position 256 * center, left, right, top, bottom, ou combinaisons ("top left") 273 * Indication de position de la découpe : 274 * - `center`, `left`, `right`, `top`, `bottom`, 275 * - ou combinaisons de plusiers `top left` 276 * - ou indication en pixels depuis une position `top=50` ou composée `top=40 left=50` 277 * - ou nom d'une fonction spéciale qui calculera et retournera la position souhaitée 257 278 * @param string $background_color 258 * couleur de fond si on agrandit l'image279 * Couleur de fond si on agrandit l'image 259 280 * @return string 260 * balise image recadree281 * balise image recadrée 261 282 */ 262 283 function image_recadre($im, $width, $height, $position = 'center', $background_color = 'white') … … 264 285 $fonction = array('image_recadre', func_get_args()); 265 286 $image = _image_valeurs_trans($im, "recadre-$width-$height-$position-$background_color",false,$fonction); 266 287 267 288 if (!$image) return(""); 268 289 … … 295 316 if ($width==0) $width=$x_i; 296 317 if ($height==0) $height=$y_i; 297 318 298 319 $offset_width = $x_i-$width; 299 320 $offset_height = $y_i-$height; 300 321 $position=strtolower($position); 301 if (strpos($position,'left')!==FALSE){ 322 323 if (strpos($position,'left')!==FALSE) { 302 324 if (preg_match(';left=(\d{1}\d+);', $position, $left)){ 303 $offset_width=$left[1]; 304 } 305 else{ 325 $offset_width=$left[1]; 326 } else { 306 327 $offset_width=0; 307 328 } 308 } 309 elseif (strpos($position,'right')!==FALSE) 329 } elseif (strpos($position,'right')!==FALSE) { 310 330 $offset_width=$offset_width; 311 else331 } else { 312 332 $offset_width=intval(ceil($offset_width/2)); 313 314 if (strpos($position,'top')!==FALSE){ 333 } 334 335 if (strpos($position,'top')!==FALSE) { 315 336 if (preg_match(';top=(\d{1}\d+);', $position, $top)){ 316 337 $offset_height=$top[1]; 317 } 318 else{ 338 } else { 319 339 $offset_height=0; 320 340 } 321 } 322 elseif (strpos($position,'bottom')!==FALSE) 341 } elseif (strpos($position,'bottom')!==FALSE) { 323 342 $offset_height=$offset_height; 324 else343 } else { 325 344 $offset_height=intval(ceil($offset_height/2)); 326 345 } 346 327 347 $im = $image["fichier"]; 328 348 $dest = $image["fichier_dest"]; 329 349 330 350 $creer = $image["creer"]; 331 351 332 352 if ($creer) { 333 353 $im = $image["fonction_imagecreatefrom"]($im); … … 337 357 @imagesavealpha($im_,true); 338 358 339 if ($background_color=='transparent') 359 if ($background_color=='transparent') { 340 360 $color_t = imagecolorallocatealpha( $im_, 255, 255, 255 , 127 ); 341 else {361 } else { 342 362 $bg = _couleur_hex_to_dec($background_color); 343 363 $color_t = imagecolorallocate( $im_, $bg['red'], $bg['green'], $bg['blue']); … … 350 370 imagedestroy($im); 351 371 } 352 353 return _image_ecrire_tag($image, array('src'=>$dest,'width'=>$width,'height'=>$height));372 373 return _image_ecrire_tag($image, array('src'=>$dest, 'width'=>$width, 'height'=>$height)); 354 374 } 355 375
Note: See TracChangeset
for help on using the changeset viewer.