Exemple #1
0
 private function resizeProfileImage(FilesystemInterface $_filesystem, \int $user_id)
 {
     $_user = User::find($this->_pdo, $user_id);
     $_file = $_user->getImageFile($_filesystem);
     $_img = GDImageManipulator::read($_file);
     $_img->resize(User::PROFILE_IMAGE_WIDTH, User::PROFILE_IMAGE_HEIGHT);
     $_file->write($_img->getStream($_file->getExtension()));
     unset($_user, $_file, $_img);
 }
Exemple #2
0
$_pdo = new \FMA\PDO\MySQL_PDO();
$_auth = new \FMA\Auth\SessionAuth($_pdo);
$router = new AltoRouter([], "/image");
$_fs = \FMA\Config::getFileSystem();
$router->map("GET", "/profile/[small|medium|large:size]/[i:id]/", function ($size, $id) use($_pdo, $_fs, $_auth) {
    $user = \FMA\User\User::find($_pdo, $id);
    if (is_null($user)) {
        return;
    }
    $img = $user->getImageFile($_fs);
    $file_name = strtolower($user->getNameFirst() . "-" . $user->getNameLast() . "." . $img->getExtension());
    header("Content-Disposition: inline; filename=\"" . $file_name . "\"");
    if (is_null($img) || !$img->isImage()) {
        return;
    }
    $_im = \FMA\Image\GDImageManipulator::read($img);
    if ($size == "medium") {
        $_im->resize("50%", "50%");
    } else {
        if ($size == "small") {
            $_im->resize("25%", "25%");
        }
    }
    $_im->output($img->getExtension());
});
$match = $router->match();
if ($match && !is_callable($match["target"])) {
    throw new TypeError("Target is not callable.");
} else {
    if ($match && is_callable($match["target"])) {
        $page_title = $match["name"];