- list($this->x, $this->y, $this->mimetype) = $image_infos;
-
- switch ($this->mimetype) {
- case 1: $this->mimetype = "gif"; break;
- case 2: $this->mimetype = "jpeg"; break;
- case 3: $this->mimetype = "png"; break;
- default:
- $page->trig("Type d'image invalide");
- return false;
- }
-
- if (strlen($_data) > SIZE_MAX) {
- $img = imagecreatefromstring($_data);
- if (!$img) {
- $page->trig("image trop grande et impossible à retailler automatiquement");
- return false;
- }
-
- $nx = $x = imagesx($img);
- $ny = $y = imagesy($img);
-
- if ($nx > 240) { $ny = intval($ny*240/$nx); $nx = 240; }
- if ($ny > 300) { $ny = intval($nx*300/$nx); $ny = 300; }
- if ($nx < 160) { $ny = intval($ny*160/$nx); $nx = 160; }
-
- $comp = '90';
- $file = tempnam('/tmp', 'photo');
-
- while (strlen($_data) > SIZE_MAX) {
- $img2 = imagecreatetruecolor($nx, $ny);
- imagecopyresampled($img2, $img, 0, 0, 0, 0, $nx, $ny, $x, $y);
- imagejpeg($img2, $file, $comp);
- $_data = file_get_contents($file);
- $this->mimetype = 'jpeg';