Exemplo n.º 1
0
function AddPicture($year, $uploadedFile, $personID, $personImages)
{
    $personPicsDir = PersonPicsDir($personID);
    if (!file_exists($personPicsDir)) {
        mkdir($personPicsDir);
    }
    $smallFile = "{$personPicsDir}/small.png";
    if (file_exists($smallFile)) {
        unlink($smallFile);
    }
    imagejpeg($dest, "{$personPicsDir}/{$year}.jpg");
    $img = imagecreatefromjpeg($uploadedFile);
    $width = imagesx($img);
    $height = imagesy($img);
    $aspect = $height / $width;
    $dest = imagecreatetruecolor(400, 500);
    // aspect 1.25
    if ($aspect < 1.25) {
        // eg. 0.8, leaves gap to left and right in original . vertically taken fully
        $zoom = 500.0 / $height;
        $src_y = 0;
        $src_w = 400.0 / $zoom;
        $src_h = 500.0 / $zoom;
        $src_x = ($width - $src_w) * 0.5;
    } else {
        $zoom = 400.0 / $width;
        $src_x = 0;
        $src_w = 400.0 / $zoom;
        $src_h = 500.0 / $zoom;
        $src_y = ($height - $src_h) * 0.5;
    }
    imagecopyresampled($dest, $img, 0, 0, $src_x, $src_y, 400, 500, $src_w, $src_h);
    imagejpeg($dest, "{$personPicsDir}/{$year}.jpg");
    imagedestroy($img);
    imagedestroy($dest);
    $personImages->AppendChild("<Image Year='{$year}'>{$year}.jpg</Image>");
}
Exemplo n.º 2
0
function CreateThumbnails()
{
    $family = LoadFamilyData();
    foreach ($family->Elements("Person") as $person) {
        $PersonID = $person->id;
        if ($person->ElementExists("Images/Image")) {
            $picDir = PersonPicsDir($PersonID);
            $smallFile = "{$picDir}/small.png";
            if (!file_exists($smallFile)) {
                $largePicName = $person->Element("Images/Image[last()]")->InnerText;
                $large = imagecreatefromjpeg("{$picDir}/{$largePicName}");
                $small = imagecreatetruecolor(80, 100);
                // aspect 1.25
                imagecopyresampled($small, $large, 0, 0, 0, 0, 80, 100, imagesx($large), imagesy($large));
                imagepng($small, $smallFile);
                imagedestroy($large);
                imagedestroy($small);
            }
        }
    }
}