/**
  * Upload new image file
  * 
  * @param array $a_upload
  * @return bool
  */
 function uploadImage(array $a_upload)
 {
     if (!$this->id) {
         return false;
     }
     $this->deleteImage();
     // #10074
     $clean_name = preg_replace("/[^a-zA-Z0-9\\_\\.\\-]/", "", $a_upload["name"]);
     $path = $this->initStorage($this->id);
     $original = "org_" . $this->id . "_" . $clean_name;
     $thumb = "thb_" . $this->id . "_" . $clean_name;
     $processed = $this->id . "_" . $clean_name;
     if (@move_uploaded_file($a_upload["tmp_name"], $path . $original)) {
         chmod($path . $original, 0770);
         $blga_set = new ilSetting("blga");
         $dimensions = $blga_set->get("banner_width") . "x" . $blga_set->get("banner_height");
         // take quality 100 to avoid jpeg artefacts when uploading jpeg files
         // taking only frame [0] to avoid problems with animated gifs
         $original_file = ilUtil::escapeShellArg($path . $original);
         $thumb_file = ilUtil::escapeShellArg($path . $thumb);
         $processed_file = ilUtil::escapeShellArg($path . $processed);
         ilUtil::execConvert($original_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
         ilUtil::execConvert($original_file . "[0] -geometry " . $dimensions . "! -quality 100 JPEG:" . $processed_file);
         $this->setImage($processed);
         return true;
     }
     return false;
 }
 /**
  * Upload video preview picture
  *
  * @param
  * @return
  */
 function generatePreviewPic($a_width, $a_height)
 {
     $item = $this->getMediaItem("Standard");
     if ($item->getLocationType() == "LocalFile" && is_int(strpos($item->getFormat(), "image/"))) {
         $dir = ilObjMediaObject::_getDirectory($this->getId());
         $file = $dir . "/" . $item->getLocation();
         if (is_file($file)) {
             if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
                 ilUtil::execConvert($file . "[0] -geometry " . $a_width . "x" . $a_height . "^ -gravity center -extent " . $a_width . "x" . $a_height . " PNG:" . $dir . "/mob_vpreview.png");
             } else {
                 ilUtil::convertImage($file, $dir . "/mob_vpreview.png", "PNG", $a_width . "x" . $a_height);
             }
         }
     }
 }
 /**
  * Upload user image
  */
 function uploadUserPicture()
 {
     global $ilUser;
     if ($this->workWithUserSetting("upload")) {
         if (!$this->form->hasFileUpload("userfile")) {
             if ($this->form->getItemByPostVar("userfile")->getDeletionFlag()) {
                 $ilUser->removeUserPicture();
             }
             return;
         } else {
             $webspace_dir = ilUtil::getWebspaceDir();
             $image_dir = $webspace_dir . "/usr_images";
             $store_file = "usr_" . $ilUser->getID() . "." . "jpg";
             // store filename
             $ilUser->setPref("profile_image", $store_file);
             $ilUser->update();
             // move uploaded file
             $uploaded_file = $this->form->moveFileUpload($image_dir, "userfile", "upload_" . $ilUser->getId() . "pic");
             if (!$uploaded_file) {
                 ilUtil::sendFailure($this->lng->txt("upload_error", true));
                 $this->ctrl->redirect($this, "showProfile");
             }
             chmod($uploaded_file, 0770);
             // take quality 100 to avoid jpeg artefacts when uploading jpeg files
             // taking only frame [0] to avoid problems with animated gifs
             $show_file = "{$image_dir}/usr_" . $ilUser->getId() . ".jpg";
             $thumb_file = "{$image_dir}/usr_" . $ilUser->getId() . "_small.jpg";
             $xthumb_file = "{$image_dir}/usr_" . $ilUser->getId() . "_xsmall.jpg";
             $xxthumb_file = "{$image_dir}/usr_" . $ilUser->getId() . "_xxsmall.jpg";
             $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
             $show_file = ilUtil::escapeShellArg($show_file);
             $thumb_file = ilUtil::escapeShellArg($thumb_file);
             $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
             $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
             if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file);
             } else {
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
                 ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
             }
         }
     }
     //		$this->saveProfile();
 }
Example #4
0
 /**
  * Upload new image file
  * 
  * @param array $a_upload
  * @return bool
  */
 function uploadImage(array $a_upload, $a_clone = false)
 {
     if (!$this->id) {
         return false;
     }
     $this->deleteImage();
     // #10074
     $clean_name = preg_replace("/[^a-zA-Z0-9\\_\\.\\-]/", "", $a_upload["name"]);
     $path = $this->initStorage($this->id);
     $original = "org_" . $this->id . "_" . $clean_name;
     $thumb = "thb_" . $this->id . "_" . $clean_name;
     $processed = $this->id . "_" . $clean_name;
     $success = false;
     if (!$a_clone) {
         $success = @move_uploaded_file($a_upload["tmp_name"], $path . $original);
     } else {
         $success = @copy($a_upload["tmp_name"], $path . $original);
     }
     if ($success) {
         chmod($path . $original, 0770);
         // take quality 100 to avoid jpeg artefacts when uploading jpeg files
         // taking only frame [0] to avoid problems with animated gifs
         $original_file = ilUtil::escapeShellArg($path . $original);
         $thumb_file = ilUtil::escapeShellArg($path . $thumb);
         $processed_file = ilUtil::escapeShellArg($path . $processed);
         ilUtil::execConvert($original_file . "[0] -geometry \"100x100>\" -quality 100 PNG:" . $thumb_file);
         ilUtil::execConvert($original_file . "[0] -geometry \"" . self::getImageSize() . ">\" -quality 100 PNG:" . $processed_file);
         $this->setImage($processed);
         return true;
     }
     return false;
 }
 /**
  * resize image
  *
  * @param	string		$a_from				source file
  * @param	string		$a_to				target file
  * @param	string		$a_width			target width
  * @param	string		$a_height			target height
  * @static
  * 
  */
 public static function resizeImage($a_from, $a_to, $a_width, $a_height, $a_constrain_prop = false)
 {
     if ($a_constrain_prop) {
         $size = " -geometry " . $a_width . "x" . $a_height . " ";
     } else {
         $size = " -resize " . $a_width . "x" . $a_height . "! ";
     }
     $convert_cmd = ilUtil::escapeShellArg($a_from) . " " . $size . ilUtil::escapeShellArg($a_to);
     ilUtil::execConvert($convert_cmd);
 }
 function createPreview()
 {
     if (count($this->areas) + count($this->points) == 0) {
         return;
     }
     include_once "./Services/Utilities/classes/class.ilUtil.php";
     $convert_cmd = "-quality 100 ";
     foreach ($this->points as $point) {
         if ($point["visible"]) {
             preg_match("/(\\d+)\\s*,\\s*(\\d+)/", $point["coords"], $matches);
             $x = $matches[1];
             $y = $matches[2];
             $r = 6;
             // draw a circle at the point
             $convert_cmd .= "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth {$this->linewidth_outer} -draw \"line " . ($x - $r) . "," . ($y - $r) . " " . ($x + $r) . "," . ($y + $r) . "\" " . "-stroke " . $point["bordercolor"] . " -fill " . $point["fillcolor"] . " -strokewidth {$this->linewidth_outer} -draw \"line " . ($x + $r) . "," . ($y - $r) . " " . ($x - $r) . "," . ($y + $r) . "\" " . "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth {$this->linewidth_inner} -draw \"line " . ($x - $r) . "," . ($y - $r) . " " . ($x + $r) . "," . ($y + $r) . "\" " . "-stroke " . $point["linecolor"] . " -fill " . $point["fillcolor"] . " -strokewidth {$this->linewidth_inner} -draw \"line " . ($x + $r) . "," . ($y - $r) . " " . ($x - $r) . "," . ($y + $r) . "\" ";
         }
     }
     foreach ($this->areas as $area) {
         if ($area["visible"] and strcmp(strtolower($area["shape"]), "rect") == 0) {
             preg_match("/(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)/", $area["coords"], $matches);
             $x0 = $matches[1];
             $y0 = $matches[2];
             $x1 = $matches[3];
             $y1 = $matches[4];
             // draw a rect around the selection
             $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_outer} -draw \"rectangle " . $x0 . "," . $y0 . " " . $x1 . "," . $y1 . "\" " . "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_inner} -draw \"rectangle " . $x0 . "," . $y0 . " " . $x1 . "," . $y1 . "\" ";
         } else {
             if ($area["visible"] and strcmp(strtolower($area["shape"]), "circle") == 0) {
                 preg_match("/(\\d+)\\s*,\\s*(\\d+)\\s*,\\s*(\\d+)/", $area["coords"], $matches);
                 $x = $matches[1];
                 $y = $matches[2];
                 $r = $matches[3];
                 // draw a circle around the selection
                 $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_outer} -draw \"circle " . $x . "," . $y . " " . ($x + $r) . "," . $y . "\" " . "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_inner} -draw \"circle " . $x . "," . $y . " " . ($x + $r) . "," . $y . "\" ";
             } else {
                 if ($area["visible"] and strcmp(strtolower($area["shape"]), "poly") == 0) {
                     $obj = "polygon";
                     // draw a polygon around the selection
                     preg_match_all("/(\\d+)\\s*,\\s*(\\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
                     if (count($matches[0]) == 2) {
                         $obj = "line";
                     }
                     $convert_cmd .= "-stroke " . $area["bordercolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_outer} -draw \"{$obj} ";
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
                     }
                     $convert_cmd .= "\" ";
                     $convert_cmd .= "-stroke " . $area["linecolor"] . " -fill " . $area["fillcolor"] . " -strokewidth {$this->linewidth_inner} -draw \"{$obj} ";
                     preg_match_all("/(\\d+)\\s*,\\s*(\\d+)/", $area["coords"], $matches, PREG_PATTERN_ORDER);
                     for ($i = 0; $i < count($matches[0]); $i++) {
                         $convert_cmd .= $matches[1][$i] . "," . $matches[2][$i] . " ";
                     }
                     $convert_cmd .= "\" ";
                 }
             }
         }
     }
     $source = ilUtil::escapeShellCmd($this->imagemap_filename);
     $target = ilUtil::escapeShellCmd($this->preview_filename);
     $convert_cmd = $source . "[0] " . $convert_cmd . " " . $target;
     ilUtil::execConvert($convert_cmd);
 }
Example #7
0
 /**
  * Create a personal picture image file from a temporary image file
  *
  * @param	string $tmp_file Complete path to the temporary image file
  * @param	int	$obj_id The object id of the related user account
  * @return returns TRUE on success, otherwise FALSE
  */
 function _uploadPersonalPicture($tmp_file, $obj_id)
 {
     $webspace_dir = ilUtil::getWebspaceDir();
     $image_dir = $webspace_dir . "/usr_images";
     $store_file = "usr_" . $obj_id . "." . "jpg";
     $target_file = $image_dir . "/{$store_file}";
     chmod($tmp_file, 0770);
     // take quality 100 to avoid jpeg artefacts when uploading jpeg files
     // taking only frame [0] to avoid problems with animated gifs
     $show_file = "{$image_dir}/usr_" . $obj_id . ".jpg";
     $thumb_file = "{$image_dir}/usr_" . $obj_id . "_small.jpg";
     $xthumb_file = "{$image_dir}/usr_" . $obj_id . "_xsmall.jpg";
     $xxthumb_file = "{$image_dir}/usr_" . $obj_id . "_xxsmall.jpg";
     ilUtil::execConvert($tmp_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
     ilUtil::execConvert($tmp_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
     ilUtil::execConvert($tmp_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
     ilUtil::execConvert($tmp_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
     // store filename
     self::_writePref($obj_id, "profile_image", $store_file);
     return TRUE;
 }
 /**
  * save container icons
  */
 function saveIcons($a_big_icon, $a_small_icon, $a_tiny_icon)
 {
     global $ilDB;
     $this->createContainerDirectory();
     $cont_dir = $this->getContainerDirectory();
     // save big icon
     $big_geom = $this->ilias->getSetting("custom_icon_big_width") . "x" . $this->ilias->getSetting("custom_icon_big_height");
     $big_file_name = $cont_dir . "/icon_big.png";
     if (is_file($a_big_icon)) {
         $a_big_icon = ilUtil::escapeShellArg($a_big_icon);
         $big_file_name = ilUtil::escapeShellArg($big_file_name);
         ilUtil::execConvert($a_big_icon . "[0] -geometry " . $big_geom . " PNG:" . $big_file_name);
     }
     if (is_file($cont_dir . "/icon_big.png")) {
         ilContainer::_writeContainerSetting($this->getId(), "icon_big", 1);
     } else {
         ilContainer::_writeContainerSetting($this->getId(), "icon_big", 0);
     }
     // save small icon
     $small_geom = $this->ilias->getSetting("custom_icon_small_width") . "x" . $this->ilias->getSetting("custom_icon_small_height");
     $small_file_name = $cont_dir . "/icon_small.png";
     if (is_file($a_small_icon)) {
         $a_small_icon = ilUtil::escapeShellArg($a_small_icon);
         $small_file_name = ilUtil::escapeShellArg($small_file_name);
         ilUtil::execConvert($a_small_icon . "[0] -geometry " . $small_geom . " PNG:" . $small_file_name);
     }
     if (is_file($cont_dir . "/icon_small.png")) {
         ilContainer::_writeContainerSetting($this->getId(), "icon_small", 1);
     } else {
         ilContainer::_writeContainerSetting($this->getId(), "icon_small", 0);
     }
     // save tiny icon
     $tiny_geom = $this->ilias->getSetting("custom_icon_tiny_width") . "x" . $this->ilias->getSetting("custom_icon_tiny_height");
     $tiny_file_name = $cont_dir . "/icon_tiny.png";
     if (is_file($a_tiny_icon)) {
         $a_tiny_icon = ilUtil::escapeShellArg($a_tiny_icon);
         $tiny_file_name = ilUtil::escapeShellArg($tiny_file_name);
         ilUtil::execConvert($a_tiny_icon . "[0] -geometry " . $tiny_geom . " PNG:" . $tiny_file_name);
     }
     if (is_file($cont_dir . "/icon_tiny.png")) {
         ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 1);
     } else {
         ilContainer::_writeContainerSetting($this->getId(), "icon_tiny", 0);
     }
 }
 /**
  * Creates a preview image path from the specified source image.
  * 
  * @param string $src_img_path The source image path.
  * @param string $dest_img_path The destination image path.
  * @return bool true, if the preview was created; otherwise, false.
  */
 private function createPreviewImage($src_img_path, $dest_img_path)
 {
     // create resize argument
     $imgSize = $this->getImageSize();
     $resizeArg = $imgSize . "x" . $imgSize . (ilUtil::isWindows() ? "^" : "\\") . ">";
     // cmd: convert $src_img_path -background white -flatten -resize 280x280 -quality 85 -sharpen 0x0.5 $dest_img_path
     $args = sprintf("%s -background white -flatten -resize %s -quality %d -sharpen 0x0.5 %s", ilUtil::escapeShellArg($src_img_path), $resizeArg, $this->getImageQuality(), ilUtil::escapeShellArg($dest_img_path));
     ilUtil::execConvert($args);
     return is_file($dest_img_path);
 }
Example #10
0
 /**
  * upload user image
  *
  * (original method by ratana ty)
  */
 function uploadUserPictureObject()
 {
     global $ilUser, $rbacsystem;
     // User folder
     if ($this->usrf_ref_id == USER_FOLDER_ID and !$rbacsystem->checkAccess('visible,read', $this->usrf_ref_id)) {
         $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
     }
     // if called from local administration $this->usrf_ref_id is category id
     // Todo: this has to be fixed. Do not mix user folder id and category id
     if ($this->usrf_ref_id != USER_FOLDER_ID) {
         // check if user is assigned to category
         if (!$rbacsystem->checkAccess('cat_administrate_users', $this->object->getTimeLimitOwner())) {
             $this->ilias->raiseError($this->lng->txt("msg_no_perm_modify_user"), $this->ilias->error_obj->MESSAGE);
         }
     }
     $userfile_input = $this->form_gui->getItemByPostVar("userfile");
     if ($_FILES["userfile"]["tmp_name"] == "") {
         if ($userfile_input->getDeletionFlag()) {
             $this->object->removeUserPicture();
         }
         return;
     }
     if ($_FILES["userfile"]["size"] == 0) {
         ilUtil::sendFailure($this->lng->txt("msg_no_file"));
     } else {
         $webspace_dir = ilUtil::getWebspaceDir();
         $image_dir = $webspace_dir . "/usr_images";
         $store_file = "usr_" . $this->object->getId() . "." . "jpg";
         // store filename
         $this->object->setPref("profile_image", $store_file);
         $this->object->update();
         // move uploaded file
         $uploaded_file = $image_dir . "/upload_" . $this->object->getId() . "pic";
         if (!ilUtil::moveUploadedFile($_FILES["userfile"]["tmp_name"], $_FILES["userfile"]["name"], $uploaded_file, false)) {
             ilUtil::sendFailure($this->lng->txt("upload_error", true));
             $this->ctrl->redirect($this, "showProfile");
         }
         chmod($uploaded_file, 0770);
         // take quality 100 to avoid jpeg artefacts when uploading jpeg files
         // taking only frame [0] to avoid problems with animated gifs
         $show_file = "{$image_dir}/usr_" . $this->object->getId() . ".jpg";
         $thumb_file = "{$image_dir}/usr_" . $this->object->getId() . "_small.jpg";
         $xthumb_file = "{$image_dir}/usr_" . $this->object->getId() . "_xsmall.jpg";
         $xxthumb_file = "{$image_dir}/usr_" . $this->object->getId() . "_xxsmall.jpg";
         $uploaded_file = ilUtil::escapeShellArg($uploaded_file);
         $show_file = ilUtil::escapeShellArg($show_file);
         $thumb_file = ilUtil::escapeShellArg($thumb_file);
         $xthumb_file = ilUtil::escapeShellArg($xthumb_file);
         $xxthumb_file = ilUtil::escapeShellArg($xxthumb_file);
         if (ilUtil::isConvertVersionAtLeast("6.3.8-3")) {
             ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200^ -gravity center -extent 200x200 -quality 100 JPEG:" . $show_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100^ -gravity center -extent 100x100 -quality 100 JPEG:" . $thumb_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75^ -gravity center -extent 75x75 -quality 100 JPEG:" . $xthumb_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30^ -gravity center -extent 30x30 -quality 100 JPEG:" . $xxthumb_file);
         } else {
             ilUtil::execConvert($uploaded_file . "[0] -geometry 200x200 -quality 100 JPEG:" . $show_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 100x100 -quality 100 JPEG:" . $thumb_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 75x75 -quality 100 JPEG:" . $xthumb_file);
             ilUtil::execConvert($uploaded_file . "[0] -geometry 30x30 -quality 100 JPEG:" . $xxthumb_file);
         }
     }
 }
 /**
  * Save an icon
  * 
  * @param 	string		path to the uploaded file
  * @param 	string		size ("big", "small", "tiny" or "svg")
  * @param	string		level ("type" or "object")
  * @param	integer		type id or object id 
  */
 static function _saveIcon($a_upload_path, $a_size, $a_level, $a_id)
 {
     global $ilSetting;
     if (is_file($a_upload_path)) {
         $icon_path = self::_createWebspaceDir($a_level, $a_id) . "/" . self::_getIconName($a_size);
         if ($a_size == "svg") {
             ilUtil::moveUploadedFile($a_upload_path, 'icon', $icon_path);
         } else {
             switch ($a_size) {
                 case "small":
                     $geom = self::SMALL_ICON_SIZE;
                     break;
                 case "tiny":
                     $geom = self::TINY_ICON_SIZE;
                     break;
                 case "big":
                 default:
                     $geom = self::BIG_ICON_SIZE;
                     break;
             }
             $a_upload_path = ilUtil::escapeShellArg($a_upload_path);
             $icon_path = ilUtil::escapeShellArg($icon_path);
             ilUtil::execConvert($a_upload_path . "[0] -geometry " . $geom . " PNG:" . $icon_path);
         }
     }
 }