49 lines
1 KiB
PHP
49 lines
1 KiB
PHP
|
<?php
|
|||
|
|
|||
|
header ("Content-Type: img/jpeg");
|
|||
|
|
|||
|
function loadjpeg($imgname) {
|
|||
|
$im = @imagecreatefromjpeg($imgname); /* Tentative d'ouverture */
|
|||
|
if (!$im) { /* V<>rification */
|
|||
|
$im = imagecreate(150, 30); /* Cr<43>ation d'une image blanche */
|
|||
|
$bgc = imagecolorallocate($im, 255, 255, 255);
|
|||
|
$tc = imagecolorallocate($im, 0, 0, 0);
|
|||
|
ImageFilledRectangle($im, 0, 0, 150, 30, $bgc);
|
|||
|
/* Affichage d'un message d'erreur */
|
|||
|
imagestring($im, 1, 5, 5, "Erreur de chargement de l'image $imgname", $tc);
|
|||
|
}
|
|||
|
return $im;
|
|||
|
}
|
|||
|
|
|||
|
// ouvre l'image source
|
|||
|
$src = loadjpeg($name);
|
|||
|
|
|||
|
// r<>cup<75>re les dimensions
|
|||
|
$sx=imagesx($src);
|
|||
|
$sy=imagesy($src);
|
|||
|
|
|||
|
// applique le pourcentage
|
|||
|
if (isset($percent))
|
|||
|
{
|
|||
|
$dx=($sx*$percent)/100;
|
|||
|
$dy=($sy*$percent)/100;
|
|||
|
}
|
|||
|
|
|||
|
// dimensions par d<>faut
|
|||
|
if (!isset($dx) || !isset($dy))
|
|||
|
{
|
|||
|
$dx=135;
|
|||
|
$dy=100;
|
|||
|
}
|
|||
|
|
|||
|
// cr<63>e l'image de destination
|
|||
|
$dst=imagecreate($dx,$dy);
|
|||
|
|
|||
|
// applique le redimensionnement
|
|||
|
imagecopyresized($dst, $src, 0, 0, 0, 0, $dx, $dy, $sx,$sy);
|
|||
|
|
|||
|
// envoie l'image
|
|||
|
imagejpeg($dst);
|
|||
|
|
|||
|
?>
|