Beispiel #1
0
function resize_image($filename, $destfile = null, $width = 600, $quality = 90)
{
    try {
        require_once dirname(__DIR__) . '/Util/ImageResize.php';
        $img = new Eventviva\ImageResize($filename);
        $img->quality_jpg = $quality;
        if ($img->getSourceWidth() > $img->getSourceHeight()) {
            if ($img->getSourceWidth() < $width) {
                if ($destfile == $filename) {
                    return false;
                }
            } else {
                $img->resizeToWidth($width);
            }
        } else {
            if ($img->getSourceHeight() < $width) {
                if ($destfile == $filename) {
                    return false;
                }
            } else {
                $img->resizeToHeight($width);
            }
        }
        if ($destfile === null) {
            $destfile = $filename;
        }
        $img->save($destfile);
        return true;
    } catch (Exception $e) {
    }
    return false;
}
Beispiel #2
0
 function handleAddPhoto($request)
 {
     if (isset($request['photoUrl'])) {
         try {
             // create thumb
             if (!file_exists('./photos/' . $this->currentUser->userid . '/thumbs')) {
                 mkdir('./photos/' . $this->currentUser->userid . '/thumbs', 0777, TRUE);
             }
             $image = new \Eventviva\ImageResize('./photos/' . $this->currentUser->userid . '/' . $request['photoUrl']);
             $image->resizeToHeight(1080);
             $image->save('./photos/' . $this->currentUser->userid . '/' . $request['photoUrl'], null, 90);
             $image->resizeToHeight(200);
             $image->save('./photos/' . $this->currentUser->userid . '/thumbs/' . $request['photoUrl']);
             //end create thumb
             try {
                 $this->storePhotoToDB($request);
             } catch (Exception $e) {
                 //var_dump($e);
                 $_SESSION['message'] = 'Fail to store photo ' . $request['photoUrl'] . ' into the database. : ' . $e->getMessage();
                 $_SESSION['messageStatus'] = 'error';
                 exit;
             }
             $_SESSION['message'] = 'Image ' . $request['photoUrl'] . ' added to db and thumbnail created';
             $_SESSION['messageStatus'] = 'success';
         } catch (Exception $e) {
             // var_dump($e);
             // exit();
             $_SESSION['message'] = 'Fail to create thumbnail for Image ' . $request['photoUrl'];
             $_SESSION['messageStatus'] = 'error';
         }
     } else {
         $_SESSION['message'] = 'No photoUrl given';
         $_SESSION['messageStatus'] = 'error';
     }
 }