n/oldblog
Archived
1
0
Fork 0
This repository has been archived on 2024-02-13. You can view files and clone it, but cannot push or open issues or pull requests.
oldblog/images/lechat/scalejpeg.php

49 lines
1 KiB
PHP
Raw Permalink Normal View History

2023-04-30 21:28:42 +02:00
<?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);
?>