本文整理汇总了PHP中Image::setWidth方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::setWidth方法的具体用法?PHP Image::setWidth怎么用?PHP Image::setWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::setWidth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getUserImageByUserId
function getUserImageByUserId($userId, $width = 200)
{
$pic = getUserImagePath($userId);
$ret = new Image($pic);
$ret->setWidth($width);
//$ret = "<img src='" .$pic ."' width='" .$width ."'>";
return $ret;
}
示例2: getImageForKategorie
function getImageForKategorie($katId)
{
$sql = "SELECT * FROM stadt_kategorien k WHERE id = " . $katId;
$result = $_SESSION['config']->DBCONNECT->executeQuery($sql);
$row = mysql_fetch_array($result);
if (strlen($row['symbolpic']) > 0) {
$file = dirname($_SERVER['SCRIPT_NAME']) . "/pics/kategoriesymbole/" . $row['symbolpic'];
$img = new Image($file);
$img->setToolTip($row['name']);
$img->setGenerated(false);
$img->setWidth(100);
return $img;
}
return new Text("");
}
示例3: getImagesHTML
public static function getImagesHTML()
{
global $REX;
$return = [];
/**
* prepare images from MetaInfo
*/
if (self::$curArticle->getValue('art_open_graph_images')) {
$images = explode(',', self::$curArticle->getValue('art_open_graph_images'));
foreach ($images as $image) {
$ogImage = new Image();
$image = \OOMedia::getMediaByFileName($image);
if (false && \rex_addon::isActivated('seo42')) {
$ogImage->setUrl(\seo42::getMediaUrl($image));
} else {
$ogImage->setUrl($REX['SERVER'] . $REX['MEDIA_DIR'] . '/' . $image->getFileName());
}
$ogImage->setType($image->getType());
$ogImage->setWidth($image->getWidth());
$ogImage->setHeigt($image->getHeight());
self::addImage($ogImage);
}
}
/** @var Image $image */
foreach (self::$images as $image) {
$return[] = '<meta property="og:image" content="' . $image->getUrl() . '">';
if ($image->getSecureUrl() || $REX['ADDON']['open_graph']['settings']['https']) {
if (!$image->getSecureUrl()) {
if (strpos($image->getUrl(), $REX['SERVER']) == 0) {
$image->setSecureUrl(str_replace('http://', 'https://', $image->getUrl()));
}
}
if ($image->getSecureUrl()) {
$return[] = '<meta property="og:image:secure_url" content="' . $image->getSecureUrl() . '">';
}
}
if ($image->getWidth()) {
$return[] = '<meta property="og:image:width" content="' . $image->getWidth() . '">';
}
if ($image->getHeigt()) {
$return[] = '<meta property="og:image:height" content="' . $image->getHeigt() . '">';
}
if ($image->getType()) {
$return[] = '<meta property="og:image:type" content="' . $image->getType() . '">';
}
}
return implode("\n\t", $return) . "\n\t";
}
示例4: ButtonBack
$menu->setYPos(190);
$menu->show();
/* --------------------------------- */
/* ------------------------------------
Statischer Zurück-Button
------------------------------------ */
$backButton = new ButtonBack();
$backButton->setXPos($MAINFRAME['xpos'] + $MAINFRAME['width'] - 83);
$backButton->setYPos($MAINFRAME['ypos'] + $MAINFRAME['border'] + 2);
$backButton->show();
/* --------------------------------- */
/* ------------------------------------
Banner
------------------------------------ */
if (isset($BANNER['activ']) && $BANNER['activ']) {
$banner = new Image($BANNER_PIC);
//$BANNER_PIC wird in Public_Vars definiert
$banner->setXPos(200);
$banner->setYPos(5);
$banner->setWidth(600);
$banner->setHeight(80);
$banner->show();
}
/* --------------------------------- */
/* ------------------------------------
BENUTZERSTATUS ANZEIGEN
------------------------------------ */
if ($USER_STATUS['aktiv']) {
$CONFIG->CURRENTUSER->showStatus($USER_STATUS['xpos'], $USER_STATUS['ypos']);
}
/* --------------------------------- */
示例5: setSize
public function setSize($size)
{
if (empty($this->data)) {
throw new \Exception('Data must be set first');
}
$this->originalSize = $size;
$this->moduleSize = ceil($this->originalSize / $this->cols);
$size = $this->moduleSize * $this->cols;
parent::setWidth($size);
parent::setHeight($size);
return $this;
}
示例6: getControlArtIconSrc
/**
* Liefert das Grafik-Symbol zurück (als HTML String),
* welches zur Alarmgeber-Art passt.
*/
function getControlArtIconSrc($tooltipActive = true)
{
$lnkImg = new Image($this->PIC);
$lnkImg->setWidth($this->CONTROL_IMAGE_WIDTH);
if ($tooltipActive) {
$ttt = $this->getIconTooltip();
$lnkImg->setToolTip($ttt);
}
$lnkImgSrc = $lnkImg->getImgSrc($this->PIC);
return $lnkImgSrc;
}
示例7: getCheckmark
/**
* Returns HTML code for either a checked or unchecked icon
* for indicating yes/no status
*
* For the time being, the unchecked status is represented by
* an empty space, aka pixel.gif
* @param boolean $status If true, the checked box is returned,
* the unchecked otherwise
* @return string The HTML code with the checkbox icon
* @todo There should be an unchecked icon other than "pixel.gif"
*/
static function getCheckmark($status = '')
{
$objImage = new Image();
$objImage->setPath($status ? self::ICON_STATUS_CHECKED : self::ICON_STATUS_UNCHECKED);
$objImage->setWidth(16);
$objImage->setHeight(16);
$checkmark_html = self::getImageOriginal($objImage, 'border="0"');
return $checkmark_html;
}
示例8: usersPage
//.........这里部分代码省略.........
if (file_exists($path)) {
$data = simplexml_load_file($path);
foreach ($data->data as $data) {
if (isset($data->username) && isset($data->lastname) && isset($data->firstname) && isset($data->student_number) && isset($data->promo) && isset($data->cesure)) {
$username = $data->username;
$lastname = $data->lastname;
$firstname = $data->firstname;
$student_number = $data->student_number;
$promo = $data->promo;
$cesure = $data->cesure;
if (!$this->model->checkuser($username, 2)) {
$this->model->insertStudents($username, utf8_decode($lastname), utf8_decode($firstname), $student_number, $promo, $cesure);
} else {
array_push($student, $username);
}
} else {
throw new Exception(__('ADMIN_UPLOAD_ERROR2'));
}
}
} else {
throw new Exception(__('ADMIN_UPLOAD_ERROR'));
}
FILE::delete($path);
$this->set('fail', $student);
}
/*
* Enregistrement des avatars
*/
if (isset($_FILES['avatar_photo']) && is_array($_FILES['avatar_photo']['name'])) {
foreach ($_FILES['avatar_photo']['size'] as $size) {
if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
}
}
$student = array();
if ($avatarpaths = File::upload('avatar_photo')) {
foreach ($avatarpaths as $avatarpath) {
$uploaded_files[] = $avatarpath;
}
foreach ($avatarpaths as $i => $avatarpath) {
$name = $_FILES['avatar_photo']['name'][$i];
try {
$img = new Image();
$img->load($avatarpath);
$type = $img->getType();
if ($type == IMAGETYPE_JPEG) {
$ext = 'jpg';
} else {
if ($type == IMAGETYPE_GIF) {
$ext = 'gif';
} else {
if ($type == IMAGETYPE_PNG) {
$ext = 'png';
} else {
throw new Exception();
}
}
}
if ($img->getWidth() > 800) {
$img->setWidth(800, true);
}
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarpath);
// Thumb
$avatarthumbpath = $avatarpath . '.thumb';
$img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarthumbpath);
unset($img);
$uploaded_files[] = $avatarthumbpath;
$student_data['avatar_path'] = $avatarthumbpath;
$student_data['avatar_big_path'] = $avatarpath;
$student_data['student_number'] = preg_replace('/\\.[a-z0-9]+$/i', '', $name);
if (isset($student_data['avatar_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_path'])) {
$avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], true);
$avatar_dir = File::getPath($avatar_path);
if (!is_dir($avatar_dir)) {
File::makeDir($avatar_dir, 0777, true);
}
File::rename($student_data['avatar_path'], $avatar_path);
}
if (isset($student_data['avatar_big_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_big_path'])) {
$avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], false);
$avatar_dir = File::getPath($avatar_path);
if (!is_dir($avatar_dir)) {
File::makeDir($avatar_dir, 0777, true);
}
File::rename($student_data['avatar_big_path'], $avatar_path);
}
} catch (Exception $e) {
array_push($student, $name);
}
}
$this->set('fail2', $student);
foreach ($uploaded_files as $uploaded_file) {
File::delete($uploaded_file);
}
}
}
}
示例9: add
/**
* Add a group
*/
public function add($params)
{
$this->setView('add.php');
$this->setTitle(__('GROUP_ADD_TITLE'));
$is_logged = isset(User_Model::$auth_data);
$is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
// Authorization
if (!$is_admin) {
throw new ActionException('Page', 'error404');
}
$group = array();
// Saving data
if (isset($_POST['name']) && isset($_POST['creation_date']) && isset($_POST['mail']) && isset($_POST['description'])) {
$uploaded_files = array();
try {
// Members
$members = array();
if (isset($_POST['members_ids']) && is_array($_POST['members_ids'])) {
foreach ($_POST['members_ids'] as $id) {
if (ctype_digit($id)) {
$id = (int) $id;
$members[$id] = array('title' => isset($_POST['member_title_' . $id]) ? $_POST['member_title_' . $id] : '', 'admin' => isset($_POST['member_admin_' . $id]));
}
}
}
// Other info
$data = array('name' => $_POST['name'], 'creation_date' => $_POST['creation_date'], 'mail' => $_POST['mail'], 'description' => $_POST['description'], 'members' => $members);
// Avatar
if (isset($_FILES['avatar']) && !is_array($_FILES['avatar']['name'])) {
if ($_FILES['avatar']['size'] > Config::UPLOAD_MAX_SIZE_PHOTO) {
throw new FormException('avatar');
}
if ($avatarpath = File::upload('avatar')) {
$uploaded_files[] = $avatarpath;
try {
$img = new Image();
$img->load($avatarpath);
$type = $img->getType();
if ($type == IMAGETYPE_JPEG) {
$ext = 'jpg';
} else {
if ($type == IMAGETYPE_GIF) {
$ext = 'gif';
} else {
if ($type == IMAGETYPE_PNG) {
$ext = 'png';
} else {
throw new Exception();
}
}
}
if ($img->getWidth() > 800) {
$img->setWidth(800, true);
}
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarpath);
// Thumb
$avatarthumbpath = $avatarpath . '.thumb';
$img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarthumbpath);
unset($img);
$uploaded_files[] = $avatarthumbpath;
$data['avatar_path'] = $avatarthumbpath;
$data['avatar_big_path'] = $avatarpath;
} catch (Exception $e) {
throw new FormException('avatar');
}
}
}
$url_name = $this->model->create($data);
Routes::redirect('group', array('group' => $url_name));
} catch (FormException $e) {
foreach ($uploaded_files as $uploaded_file) {
File::delete($uploaded_file);
}
foreach ($data as $key => $value) {
$group[$key] = $value;
}
$group['members'] = Student_Model::getInfoByUsersIds(array_keys($members));
foreach ($group['members'] as &$member) {
if (isset($members[(int) $member['user_id']])) {
$member['title'] = $members[(int) $member['user_id']]['title'];
$member['admin'] = $members[(int) $member['user_id']]['admin'] ? '1' : '0';
}
}
$this->set('form_error', $e->getError());
}
}
$this->set('group', $group);
$this->addJSCode('Group.initEdit();');
}
示例10: Table
$_SESSION['config']->PUBLICVARS['currentMode'] = $_REQUEST['changeMode'];
}
$topSpaceTable = new Table(array(""));
$topSpaceTable->show();
$layoutTable = new Table(array(""));
$layoutTable->setWidth($bannerWidth);
$layoutTable->setAlign("left");
$layoutTable->setBORDER(0);
$layoutTable->setBackgroundColor($_SESSION['config']->COLORS['panel_background']);
$layoutTable->setSpacing(0);
$layoutTable->setPadding(0);
/* ------------------------------------
BANNER
------------------------------------ */
$banner = new Image("pics/Banner.png");
$banner->setWidth($bannerWidth);
if (!$noFrameLayout) {
$banner->setGenerated(false);
$contentLayoutRow1 = $layoutTable->createRow();
$contentLayoutRow1->setAlign("left");
$contentLayoutRow1->setAttribute(0, $banner);
$contentLayoutRow1->setStyle("padding", "10px");
$layoutTable->addRow($contentLayoutRow1);
} else {
$_SESSION['additionalLayoutHeight'] = 15;
$bannerHeight = $_SESSION['additionalLayoutHeight'];
}
$modeSwitchComboTbl = new Table(array(""));
$modeSwitchComboTbl->setWidth(100);
$modeSwitchComboTbl->setAlign("center");
$modeSwitchComboTbl->setVAlign("middle");
示例11: getSensorArtIconSrc
/**
* Liefert das Grafik-Symbol zurück (Image),
* welches zur Sensor-Art passt.
*/
function getSensorArtIconSrc($tooltip = true, $width = 0)
{
$lnkImg = new Image($this->PIC);
$lnkImg->setWidth($width == 0 ? $this->CONTROL_IMAGE_WIDTH : $width);
if ($tooltip) {
$ttt = $this->getIconTooltip();
$lnkImg->setToolTip($ttt);
}
$lnkImgSrc = $lnkImg->getImgSrc($this->PIC);
return $lnkImgSrc;
}
示例12: index
//.........这里部分代码省略.........
}
if (isset($liste[7])) {
$city = $liste[7];
}
if (isset($liste[8])) {
$cellphone = $liste[8];
}
if (isset($liste[9])) {
$phone = $liste[9];
}
if (isset($liste[10])) {
$birthday = $liste[10];
}
if (!$this->model->checkuser($username, 1)) {
$this->model->insertUsers(trim($username), trim($admin), trim($mail), trim($msn), trim($jabber), trim($address), trim($zipcode), trim($city), trim($cellphone), trim($phone), trim($birthday));
}
}
}
fclose($fp);
if (file_exists($path . 'students.csv')) {
$fp = fopen($path . 'students.csv', "r");
} else {
throw new Exception(__('ADMIN_POST_CSVERROR2'));
}
$i = 0;
while (!feof($fp)) {
$i = $i + 1;
// Tant qu'on n'atteint pas la fin du fichier
$ligne = fgets($fp, 4096);
/* On lit une ligne */
// On récupère les champs séparés par ; dans liste
$liste = explode(";", $ligne);
// On assigne les variables
if (strlen($liste[0]) > 1) {
if (isset($liste[0])) {
$username = $liste[0];
}
if (isset($liste[1])) {
$lastname = $liste[1];
}
if (isset($liste[2])) {
$firstname = $liste[2];
}
if (isset($liste[3])) {
$student_number = $liste[3];
}
if (isset($liste[4])) {
$promo = $liste[4];
}
if (isset($liste[5])) {
$cesure = $liste[5];
}
if (!$this->model->checkuser($username, 2)) {
$this->model->insertStudents(trim($username), trim($lastname), trim($firstname), trim($student_number), trim($promo), trim($cesure));
}
// On déplace et formate les photos dans le dossier avatars
$avatarpath = $path . 'photos_students/' . $student_number . '.jpg';
$img = new Image();
$img->load($avatarpath);
$type = $img->getType();
if ($type == IMAGETYPE_JPEG) {
$ext = 'jpg';
} else {
if ($type == IMAGETYPE_GIF) {
$ext = 'gif';
} else {
if ($type == IMAGETYPE_PNG) {
$ext = 'png';
} else {
throw new Exception();
}
}
}
if ($img->getWidth() > 800) {
$img->setWidth(800, true);
}
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarpath);
// Thumb
$avatarthumbpath = $path . 'photos_students/' . $student_number . '_thumb.jpg';
$img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]);
$img->setType(IMAGETYPE_JPEG);
$img->save($avatarthumbpath);
if (FILE::exists(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/')) {
FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
} else {
FILE::makeDir(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/');
}
unset($img);
}
}
fclose($fp);
// On supprime le tout du dossier temp
FILE::delete($path);
}
}
}
示例13: castToImage
public function castToImage($obj)
{
$i = new Image();
if (isset($obj->imageID)) {
$i->setImageID($obj->imageID);
}
if (isset($obj->size)) {
$i->setSize($obj->size);
}
if (isset($obj->path)) {
$i->setPath($obj->path);
}
if (isset($obj->height)) {
$i->setHeight($obj->height);
}
if (isset($obj->width)) {
$i->setWidth($obj->width);
}
if (isset($obj->partID)) {
$i->setPartID($obj->partID);
}
if (isset($obj->sort)) {
$i->setSort($obj->sort);
}
return $i;
}
示例14: show
function show()
{
//Wenn notwendig Eingabemaske, ansonsten Standard-Anzeige
if (!$this->showInsertMaskIfNeeded()) {
$rowsToShow = $this->getRowsToShow();
//Tabelle fÃÂÃÂÃÂür gesamte NEWS
$tbl = new Table(array("News"));
$tbl->setHeadEnabled(false);
$tbl->setBorder(0);
foreach ($rowsToShow as $row) {
$tt = new Text($row['Text']);
$tt->setFilter(false);
$ta = new Text($row['Autor']);
$tblxTitle = new Table(array("", ""));
$tblxTitle->setColSizes(array("50"));
$tblxTitle->setAlign("left");
$rxtitle = $tblxTitle->createRow();
$t0 = new Title(getFormatedDate($row['Datum'], "standard") . ":");
$t0->setWidth(20);
$rxtitle->setAttribute(0, $t0);
$t1 = new Title($row['Title']);
$rxtitle->setAttribute(1, $t1);
$rxtitle->setAlign("left");
$tblxTitle->addRow($rxtitle);
//Tabelle fÃÂÃÂÃÂür den jeweiligen Eintrag
$tblx = new Table(array(""));
if (strlen($row['pic']) > 0) {
$tblx = new Table(array("", ""));
$tblx->setColSizes(array("180"));
}
$tblx->setBorder($this->CONFIG->GB_CONFIG['border']);
$tblx->setWidth("100%");
//TEXT
$rx = $tblx->createRow();
if (strlen($row['pic']) > 0 && !(isset($_REQUEST['removeNewsPicId']) && $_REQUEST['removeNewsPicId'] == $row['id'])) {
$img = new Image($row['pic']);
$img->setWidth(175);
$rx->setAttribute(0, $img);
$rx->setAttribute(1, $tt);
} else {
$rx->setAttribute(0, $tt);
}
$rx->setAlign("left");
$tblx->addRow($rx);
$f = new FontType();
$rx->setFonttypes(array(0 => $f));
$f = new FontType();
$f->setFontsize(1);
$f->setItalic(false);
$rx->setFonttypes(array(0 => $f));
$r = $tbl->createRow();
$r->setAttribute(0, $tblxTitle);
$tbl->addRow($r);
$r1 = $tbl->createRow();
$r1->setAttribute(0, $tblx);
$tbl->addRow($r1);
$ytElem = new YouTubeElement($row['yt_video'], "news", "yt_video", $row['id']);
$r1 = $tbl->createRow();
$r1->setAttribute(0, $ytElem);
$tbl->addRow($r1);
$tbl->addSpacer(0, 7);
if ($_SESSION['config']->CURRENTUSER->STATUS == "admin" || $_SESSION['config']->CURRENTUSER->STATUS == "user") {
$r2 = $tbl->createRow();
$xDv = new Div();
$xDv->setWidth(450);
$xDv->setHeight(40);
$txChngePic = new Text("Bild Hochladen/ÃÂÃÂÃÂÃÂndern<br>");
$txChngePic->setFilter(false);
$newPicLink = new Link("?popupRunLink=imageUploaderPopup&targetPath=pics/news&DbInsertTable=news&DbInsertCol=pic&DbInsertId=" . $row['id'] . "&stayAlive=ok", $txChngePic);
$txRemPic = new Text("Bild Entfernen<br>");
$txRemPic->setFilter(false);
$removePicLink = new Link("?removeNewsPicId=" . $row['id'] . "", $txRemPic);
$spTx = new Text(" ");
$spTx->setFilter(false);
$xDv->add($newPicLink);
if (strlen($row['pic']) > 0) {
if (isset($_REQUEST['removeNewsPicId']) && $_REQUEST['removeNewsPicId'] == $row['id']) {
$sql = "UPDATE news SET pic = null WHERE id = " . $_REQUEST['removeNewsPicId'];
$_SESSION['config']->DBCONNECT->executeQuery($sql);
} else {
$xDv->add($removePicLink);
}
}
$newPicLink->setPopup(true);
$r2->setAttribute(0, $xDv);
$tbl->addRow($r2);
}
$tbl->addSpacer(0, 35);
}
if ($_SESSION['config']->CURRENTUSER->STATUS == "admin" || $_SESSION['config']->CURRENTUSER->STATUS == "user") {
// Neuer Eintrag- BUTTON
//--------------------------------
$insertButton = new Button('dbTableNew', 'News eintragen');
$form = new Form($_SERVER['SCRIPT_NAME']);
$form->add($insertButton);
$form->show();
}
// Tabelle anzeigen
//--------------------------------
$tbl->show();
//.........这里部分代码省略.........
示例15: addAttachment
public function addAttachment($param)
{
$this->setView('iframe_add.php');
$is_logged = isset(User_Model::$auth_data);
$is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
@set_time_limit(0);
$uploaded_files = array();
$attachments = array();
try {
if ($is_admin && isset($param['id']) && isset($_FILES['attachment_photo']) && is_array($_FILES['attachment_photo']['name'])) {
foreach ($_FILES['attachment_photo']['size'] as $size) {
if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) {
throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO))));
}
}
if ($filepaths = File::upload('attachment_photo')) {
foreach ($filepaths as $filepath) {
$uploaded_files[] = $filepath;
}
foreach ($filepaths as $i => $filepath) {
$name = isset($_FILES['attachment_photo']['name'][$i]) ? $_FILES['attachment_photo']['name'][$i] : '';
try {
$img = new Image();
$img->load($filepath);
$type = $img->getType();
if ($type == IMAGETYPE_JPEG) {
$ext = 'jpg';
} else {
if ($type == IMAGETYPE_GIF) {
$ext = 'gif';
} else {
if ($type == IMAGETYPE_PNG) {
$ext = 'png';
} else {
throw new Exception();
}
}
}
if ($img->getWidth() > 800) {
$img->setWidth(800, true);
}
$img->save($filepath);
// Thumb
$thumbpath = $filepath . '.thumb';
$img->thumb(Config::$THUMBS_SIZES[0], Config::$THUMBS_SIZES[1]);
$img->setType(IMAGETYPE_JPEG);
$img->save($thumbpath);
unset($img);
$attachments[] = array($filepath, $name, $thumbpath);
$uploaded_files[] = $thumbpath;
} catch (Exception $e) {
throw new Exception(__('POST_ADD_ERROR_PHOTO_FORMAT'));
}
}
}
// Attach files
foreach ($attachments as $attachment) {
$this->model->attachFile($param['id'], $attachment[0], $attachment[1], isset($attachment[2]) ? $attachment[2] : null);
}
$this->addJSCode('
parent.location = "' . Config::URL_ROOT . Routes::getPage('post', array('id' => $param['id'])) . '";
');
}
Post_Model::clearCache();
} catch (Exception $e) {
// Delete all uploading files in tmp
foreach ($uploaded_files as $uploaded_file) {
File::delete($uploaded_file);
}
$this->addJSCode('
with(parent){
Post.errorForm(' . json_encode($e->getMessage()) . ');
}
');
}
}