return ($this = null);
}
list($this->x, $this->y, $this->mimetype) = $image_infos;
- // récupération du type de l'image
+
switch ($this->mimetype) {
- case 1:
- $this->mimetype = "gif";
- break;
-
- case 2:
- $this->mimetype = "jpeg";
- break;
-
- case 3:
- $this->mimetype = "png";
- break;
-
+ 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 ($this = null);
}
if (strlen($_data) > SIZE_MAX) {
- $page->trig("Image trop grande (max 30ko)");
- return ($this = null);
+ $img = imagecreatefromstring($_data);
+ if (!$img) {
+ $page->trig("image trop grande et impossible à retailler automatiquement");
+ return ($this = null);
+ }
+
+ $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';
+
+ $comp --;
+ }
+
+ unlink($file);
}
$this->data = $_data;
}
function stream_open($path, $mode, $options, &$opened_path)
{
- $url = parse_url($path);
- $this->varname = $url['host'];
- if(!isset($GLOBALS[$this->varname]))
+ $url = parse_url($path);
+ $this->varname = $url['host'];
+ $this->position = 0;
+ if (!isset($GLOBALS[$this->varname]))
{
trigger_error('Global variable '.$this->varname.' does not exist', E_USER_WARNING);
return false;
}
- $this->position = 0;
return true;
}
// }}}
+ // {{{ stream_close
+
+ function stream_close()
+ {
+ }
+
+ // }}}
// {{{ stream_read
function stream_read($count)
}
// }}}
+ // {{{ stream_write
+
+ function stream_write($data)
+ {
+ $len = strlen($data);
+ if ($len > $this->position + strlen($GLOBALS[$this->varname])) {
+ str_pad($GLOBALS[$this->varname], $len);
+ }
+
+ $GLOBALS[$this->varname] = substr_replace($GLOBALS[$this->varname], $data, $this->position, $len);
+ $this->position += $len;
+ }
+
+ // }}}
// {{{ stream_eof
function stream_eof()
}
// }}}
+ // {{{ stream_tell
+
+ function stream_tell()
+ {
+ return $this->position;
+ }
+
+ // }}}
+ // {{{ stream_seek
+
+ function stream_seek($offs, $whence)
+ {
+ switch ($whence) {
+ case SEEK_SET:
+ $final = $offs;
+ break;
+
+ case SEEK_CUR:
+ $final += $offs;
+ break;
+
+ case SEEK_END:
+ $final = strlen($GLOBALS[$this->varname]) + $offs;
+ break;
+ }
+
+ if ($final < 0) {
+ return -1;
+ }
+ $this->position = $final;
+ return 0;
+ }
+
+ // }}}
+ // {{{ stream_flush
+
+ function stream_flush()
+ {
+ }
+
+ // }}}
}
// }}}