/** * Méthode permettant de redimensionner une image uploadée (enregistrée en base) * http://www.site.com/statique/resize/id:2/w:200/h:200/ * * $_GET["id"] int Id de l'upload * $_GET["w"] int largeur max souhaitée * $_GET["h"] int hauteur max souhaitée * @return void */ public function resize() { if (!Form::isNumeric($_GET["id"]) || !Form::isNumeric($_GET["w"]) || !Form::isNumeric($_GET["h"])) { Go::to404(); } if (!file_exists($image = ModelUpload::getPathById($_GET["id"]))) { Go::to404(); } preg_match(File::REGEXP_EXTENSION, $image, $extract); $ext = $extract[1]; $folder_cache = "includes/applications/" . Core::$application . "/_cache/imgs/"; $file_cache = $folder_cache . "resize_" . $_GET["id"] . "_" . $_GET["w"] . "_" . $_GET["h"] . "." . $ext; if ($app != "main") { Configuration::$server_url .= "../"; } if (file_exists($file_cache)) { Header::location(Configuration::$server_url . $file_cache); } Image::createCopy($image, $file_cache, $_GET["w"], $_GET["h"]); Header::location(Configuration::$server_url . $file_cache); }
/** * Méthode permettant d'ajouter une nouvelle miniature dans la liste de traitement * @deprecated * @param $pName * @param $pFolder * @param $pWidth * @param $pHeight * @return void */ public function addMiniature($pName, $pFolder, $pWidth, $pHeight) { array_push($this->miniatures, array("pathFile" => $pFolder . $pName . "." . $this->fileType, "width" => $pWidth, "height" => $pHeight)); if ($this->isUpload) { Image::createCopy($this->pathFile, $pFolder . $pName . "." . $this->fileType, $pWidth, $pHeight); } }
public static function sample() { $i = new Image(200, 200, Image::PNG, 2); /** * Repere */ $i->setLineStyle(255, 0, 0, 2); $i->moveTo(0, 100); $i->lineTo(200, 100); $i->moveTo(100, 0); $i->lineTo(100, 200); /** * Carre */ $i->setLineStyle(127, 127, 127, 2); $i->beginFill(255, 255, 255); $i->drawRectangle(50, 50, 100, 100); $i->endFill(); /** * Cercle */ $i->setLineStyle(0, 0, 0, 0); $i->beginFill(0, 0, 255); $i->drawCircle(50, 50, 10); $i->endFill(); /** * texte */ $i->drawText("x", 10, "files/visitor2.ttf", 0, 97); $i->drawText("y", 10, "files/visitor2.ttf", 87, 10); $i->drawText("class.Image.php", 10, "files/arial.ttf", 65, 140, 45, 45, 45, 45); $i->render(); }
/** * @return void */ public function render() { if (empty($this->fontColors)) { $this->fontColors[] = "#000000"; } if (!$this->fontSizeMax) { $this->fontSizeMax = 12; } if (!$this->fontSizeMin) { $this->fontSizeMin = 12; } $distance = $this->width / $this->length; $_SESSION[self::SESSION_VAR_NAME][$this->name] = $this->value; $img = new Image($this->width, $this->height, Image::PNG, 1); if (!$this->transparent) { $img->beginFill(hexdec(substr($this->backgroundColor, 1, 2)), hexdec(substr($this->backgroundColor, 3, 2)), hexdec(substr($this->backgroundColor, 5, 2))); } $img->drawRectangle(0, 0, $this->width, $this->height); $img->endFill(); $value = $this->getValue(); for ($i = 0, $max = strlen($value); $i < $max; $i++) { $c = $this->fontColors[rand(0, count($this->fontColors) - 1)]; $f = $this->fonts[rand(0, count($this->fonts) - 1)]; $s = rand($this->fontSizeMin, $this->fontSizeMax); $img->drawText(substr($value, $i, 1), $s, $f, $distance / 4 + $i * $distance, $s + ($this->height - $s) / 2, hexdec(substr($c, 1, 2)), hexdec(substr($c, 3, 2)), hexdec(substr($c, 5, 2)), rand(-$this->rotation, $this->rotation)); } $img->render(); }