public static function createFromFile($filename, $mime_type, $objAlbum) { $objPicture = new clsPicture(); /* Decide which incoming mime type it is. */ switch ($mime_type) { case 'image/jpeg': $img = ImageCreateFromJpeg($filename); break; case 'image/png': $img = ImageCreateFromPng($filename); break; case 'image/gif': $img = ImageCreateFromGif($filename); break; default: return 'image_filetype'; } list($intWidth, $intHeight) = getImageSize($filename); $intMaxWidth = $objAlbum->get('max_width'); $intMaxHeight = $objAlbum->get('max_height'); if ($intMaxWidth <= 0) { $intMaxWidth = DEFAULT_X; } if ($intMaxHeight <= 0) { $intMaxHeight = DEFAULT_Y; } if ($intWidth > $intMaxWidth || $intHeight > $intMaxHeight) { /* Check whether the image needs to be resized vertically or horizonally more. */ if ($intWidth / $intMaxWidth > $intHeight / $intMaxHeight) { /* Right-left needs to have priority. */ $ratio = $intMaxWidth / $intWidth; } else { /* Up-down needs to have priority. */ $ratio = $intMaxHeight / $intHeight; } $intNewWidth = $intWidth * $ratio; $intNewHeight = $intHeight * $ratio; $imgNew = @ImageCreateTrueColor($intNewWidth, $intNewHeight); if (!@ImageCopyResized($imgNew, $img, 0, 0, 0, 0, $intNewWidth, $intNewHeight, $intWidth, $intHeight)) { return "image_noresize"; } $intWidth = $intNewWidth; $intHeight = $intNewHeight; ImageDestroy($img); $img = $imgNew; } /* This has to be done before setImage() because setImage() needs data from the album. */ $objPicture->set('album_id', $objAlbum->get('id')); $result = $objPicture->setImage($img); ImageDestroy($img); if ($result) { return $result; } $objPicture->set('width', $intWidth); $objPicture->set('height', $intHeight); $objPicture->save(); return $objPicture; }
$objPicture->getFromRequest(array('id', 'album_id', 'title', 'caption')); $objPicture->load(); $objPicture->getFromRequest(array('id', 'album_id', 'title', 'caption')); if ($objPicture->get('confirmed')) { /* If the picture is already confirmed, just skip this. */ $strSubAction = 'preview'; } else { if ($objPicture->get('user_id') != $user_id) { throw new Exception('exception_accessdenied'); } /* Make sure that users can only edit their own pictures. */ $objAlbum = new clsAlbum($objPicture->get('album_id')); if ($objAlbum->isNew()) { $objTemplate->setText('ERROR', "Please select an album for the picture."); } elseif ($objAlbum->canPostPicture($objUser)) { $objPicture->set('confirmed', 1); $objPicture->set('date', date('Y-m-d H:i:s')); $objPicture->save(); $objTemplate->setText('MESSAGE', "Picture has been saved [<a href='index.php?action=albums&" . $objAlbum->getIDPair() . "'>Go to album</a>]."); } else { $objTemplate->setText('ERROR', "You are not allowed to post pictures in that category."); } $strSubAction = 'preview'; } } if ($strSubAction == 'delete') { $user_id = $objUser ? $objUser->get('id') : 0; $objPicture = new clsPicture(); $objPicture->getFromRequest(); $objPicture->load(); if ($objPicture->get('user_id') != $user_id) {