function imageDualResize($filename, $cleanFilename, $wtarget, $htarget) { if (!file_exists($cleanFilename)) { $dims = getimagesize($filename); $width = $dims[0]; $height = $dims[1]; while ($width > $wtarget || $height > $htarget) { if ($width > $wtarget) { $percentage = $wtarget / $width; } if ($height > $htarget) { $percentage = $htarget / $height; } /*if($width > $height) { $percentage = ($target / $width); } else { $percentage = ($target / $height); }*/ //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); } $image = new SimpleImage(); $image->load($filename); $image->resize($width, $height); $image->save($cleanFilename); $image = null; } //returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the return "src=\"{$baseurl}/{$cleanFilename}\""; }
function InsertMemory($memorydate, $imgname, $userid, $location, $title) { global $objSmarty, $config; if ($this->con->Conectar() == true) { $memdate = $this->changeDateformut($memorydate); $memoryphoto = ""; $root_url = $_SERVER[DOCUMENT_ROOT] . '/memoryphoto/'; $location_url = $_SERVER[DOCUMENT_ROOT] . '/includes/app/pics_temp/'; if ($imgname != "") { $resizeObj = new SimpleImage($location . $imgname); if ($width >= "1000") { $resizeObj->resize(800, 650); $resizeObj->save($root_url . $imgname); } if ($width >= "800" && $width < "1000") { $resizeObj->resize(600, 460); $resizeObj->save($root_url . $imgname); } if ($width >= "600" && $width < "800") { $resizeObj->resize(400, 260); $resizeObj->save($root_url . $imgname); } $name = $imgname; //@move_uploaded_file($_FILES['memoryphoto']['tmp_name'], "memoryphoto/".$name);exit; $memoryphoto = " `MemoryPhoto` = '" . addslashes($imgname) . "', "; $resizeObj = new SimpleImage($location . $name); $resizeObj->resize(160, 160); $resizeObj->save($root_url . "thumbnail/" . $name); $memoryphotothumb = " `MemoryPhotoThumbnail` = '" . addslashes($name) . "', "; $resizeObj->resize(850, 450); $resizeObj->save($root_url . "850x450/" . $name); $resizeObj->resize(300, 290); $resizeObj->save($root_url . "300x290/" . $name); $filename = $root_url . $name; rename($location . $name, $filename); } else { //echo "ELSE";exit; $memoryphoto = " `MemoryPhoto` = 'photo_not_available.jpg', "; //$memoryphoto=" `MemoryPhoto` = ".'photo_not_available.jpg'.','; $memoryphotothumb = " `MemoryPhotoThumbnail` = 'photo_not_available.jpg', "; } $InsQuery = "INSERT INTO `tbl_mymemories` \n\t\t\tset `MemberID`= '" . $userid . "' ,\n\t\t\t`MemoryTitle`= '" . addslashes($title) . "',\n\t\t\t`MemoryDate`= '" . $memdate . "' ,\n\t\t\t{$memoryphoto} \n\t\t\t{$memoryphotothumb} \n\t\t\t`Status`= '1' ,\n\t\t\t`CreatedDateTime`= NOW()"; $insertid = mysql_query($InsQuery); $last_insert_id = mysql_insert_id(); /* Insert For Showing The Recent Activities Starts Here */ $activity_comment = "created new memory from app."; $Recent_Activity = "INSERT INTO `tbl_recent_activity` \n\t\t\t(`activity_id`, `A_MemberID`,`A_FriendID`, `Added_Page`, `Activity_Comment`, `Table_Fetch`, `PhotoId`, `Privacy`, `Status`, `createdtime`) \n\t\t\tVALUES ('','" . $userid . "','','Memory','" . $activity_comment . "','memory','" . $last_insert_id . "','1','1',now())"; $Recent_Insert = mysql_query($Recent_Activity); return "MEmory has been created successfully."; } else { return "Database Error"; } }
function insertImageSub($file, $sub_id, $menu_id) { $error = false; $arr = explode('.', $file["name"]); $imageFileType = end($arr); if ($file["size"] > 5000000) { $error = true; } if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") { $error = true; } if (!$error) { $target_dir = "../images/menu_" . $menu_id . "/sub_" . $sub_id . "/"; $target_file = $target_dir . $file["name"]; // if (!file_exists($target_dir)) { mkdir($target_dir, 0777, true); } if (file_exists($target_file)) { unlink($target_file); } if (move_uploaded_file($file["tmp_name"], $target_file)) { include 'classSimpleImage.php'; $image = new SimpleImage(); $image->load($target_file); $image->resize(218, 138); $image->save($target_file); $arr = explode("../", $target_file); return end($arr); } } else { return false; } }
public function action_index() { $tags = array(); $imager = new SimpleImage(); if ($this->request->param('path')) { // Берем новость $post = ORM::factory('blog')->where('url', '=', $this->request->param('path'))->find(); } else { $post = ORM::factory('blog'); } if ($_POST) { $post_name = Arr::get($_POST, 'post_name'); $post_url = Arr::get($_POST, 'post_url'); $short_text = Arr::get($_POST, 'short_text'); $full_text = Arr::get($_POST, 'full_text'); $tag = Arr::get($_POST, 'tag'); // Загрузка изображения $image = $_FILES["imgupload"]["name"]; if (!empty($image)) { $imager = new SimpleImage(); //$this->news->deleteImage($post->id); //$image = $this->image->upload_image($image['tmp_name'], $image['name'], $this->config->news_images_dir."big/"); move_uploaded_file($_FILES["imgupload"]["tmp_name"], "files/blog/" . $_FILES["imgupload"]["name"]); $imager->load("files/blog/" . $image); $imager->resize(200, 200); $imager->save("files/blog/miniatures/" . $image); } $post->set('name', $post_name)->set('url', $post_url)->set('date', DB::expr('now()'))->set('short_text', $short_text)->set('full_text', $full_text)->set('image', $image)->set('tag_id', ORM::factory('tags')->where('name', '=', $tag)->find())->save(); } $tags = ORM::factory('tags')->find_all(); $content = View::factory('/admin/post')->bind('tags', $tags)->bind('post', $post); $this->template->content = $content; }
function ImageResize($file) { $image = new SimpleImage(); $image->load('traffic-images/temp/' . $file); $image->resize(300, 200); $image->save('traffic-images/' . $file); unlink("traffic-images/temp/" . $file); }
public function saveImageInFile($file) { $t = $file['tmp_name']; $n = $file['name']; $path = App::get("uploads_dir_original") . DIRECTORY_SEPARATOR . $n; move_uploaded_file($t, $path); $image = new SimpleImage(); $image->load($path); $image->resize(250, 250); $image->save(App::get("uploads_dir_small") . DIRECTORY_SEPARATOR . $n); return $n; }
function scale($size = 100) { if (!$this->image && !$this->checked) { $this->get(); } if (!$this->image) { return false; } // New code to get rectangular images require_once mnminclude . "simpleimage.php"; $thumb = new SimpleImage(); $thumb->image = $this->image; if ($thumb->resize($size, $size, true)) { //$this->image = $thumb->image; //$this->x=imagesx($this->image); //$this->y=imagesy($this->image); return $thumb; } return false; }
static function Thumbnail($image_file, $thumb_file, $width = 48, $height = 48) { $ctype = FSS_Helper::datei_mime("png"); // thumb file exists if (file_exists($thumb_file) && filesize($thumb_file) > 0) { header("Content-Type: " . $ctype); header('Cache-control: max-age=' . 60 * 60 * 24 * 365); header('Expires: ' . gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365)); @readfile($thumb_file); exit; } require_once JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'helper' . DS . 'third' . DS . 'simpleimage.php'; $im = new SimpleImage(); $im->load($image_file); if (!$im->image) { // return a blank thumbnail of some sort! $im->load(JPATH_SITE . DS . 'components' . DS . 'com_fss' . DS . 'assets' . DS . 'images' . DS . 'blank_16.png'); } $im->resize($width, $height); $im->output(); $im_data = ob_get_clean(); if (strlen($im_data) > 0) { // if so use JFile to write the thumbnail image JFile::write($thumb_file, $im_data); } else { // it failed for some reason, try doing a direct write of the thumbnail $im->save($thumb_file); } header('Cache-control: max-age=' . 60 * 60 * 24 * 365); header('Expires: ' . gmdate(DATE_RFC1123, time() + 60 * 60 * 24 * 365)); header("Content-Type: " . $ctype); if (file_exists($thumb_file && filesize($thumb_file) > 0)) { @readfile($thumb_file); } else { $im->output(); } exit; }
function imageResize($filename, $cleanFilename, $target) { if (!file_exists($cleanFilename)) { $dims = getimagesize($filename); $width = $dims[0]; $height = $dims[1]; //takes the larger size of the width and height and applies the formula accordingly...this is so this script will work dynamically with any size image if ($width > $height) { $percentage = $target / $width; } else { $percentage = $target / $height; } //gets the new value and applies the percentage, then rounds the value $width = round($width * $percentage); $height = round($height * $percentage); $image = new SimpleImage(); $image->load($filename); $image->resize($width, $height); $image->save($cleanFilename); $image = null; } //returns the new sizes in html image tag format...this is so you can plug this function inside an image tag and just get the return "src=\"{$baseurl}/{$cleanFilename}\""; }
require_once "../lib/classes/Content.php"; require_once "../lib/simpleimage.php"; $adminObj = new Admin(); $ContentObj = new Content(); $ImageObj = new SimpleImage(); $adminObj->validateAdmin(); if (isset($_POST['submitForm'])) { if (empty($_POST['ModelId'])) { if ($_FILES['model_master_image']['error'] == 0) { $ModelName = mysql_real_escape_string($_POST['model_name']); $ModelMasterImage = time('his') . $_FILES['model_master_image']['name']; $path = "../uploaded_images/{$ModelMasterImage}"; $thumbPath = "../uploaded_images/thumb/{$ModelMasterImage}"; move_uploaded_file($_FILES['model_master_image']['tmp_name'], $path); $ImageObj->load($path); $ImageObj->resize(300, 300); $ImageObj->save($thumbPath); $obj->query("insert into tbl_model set model_name='{$ModelName}',model_master_image\t='{$ModelMasterImage}',status=1,add_date=CURDATE()"); $modelId = mysql_insert_id(); $obj->query("insert into tbl_model_cover_photo set model_id = '{$modelId}' , cover_image_name = '{$ModelMasterImage}' , status=1 , add_date=CURDATE()"); $commonObj->pushMessage("Model has been uploaded successfully."); $commonObj->wtRedirect("models.php"); } else { $commonObj->pushError("Opps!Error in file uploading try again."); } } else { if ($_FILES['model_master_image']['error'] == 0) { $ModelName = mysql_real_escape_string($_POST['model_name']); $ModelMasterImage = time('his') . $_FILES['model_master_image']['name']; $model_desc = mysql_real_escape_string($_POST['model_desc']); $path = "../uploaded_images/{$ModelMasterImage}";
/** * Returns array('success'=>true) or array('error'=>'error message') */ function handleUpload($uploadDirectory, $replaceOldFile = FALSE) { $folder = getcwd() . '/uploads/'; $thumbFolder = getcwd() . '/uploads/thumbs/'; if (!is_writable($uploadDirectory)) { return array('error' => "Server error. Upload directory isn't writable."); } if (!$this->file) { return array('error' => 'No files were uploaded.'); } $size = $this->file->getSize(); if ($size == 0) { return array('error' => 'File is empty'); } if ($size > $this->sizeLimit) { return array('error' => 'File is too large'); } $pathinfo = pathinfo($this->file->getName()); $filename = $pathinfo['filename']; //$filename = md5(uniqid()); $ext = $pathinfo['extension']; if ($this->allowedExtensions && !in_array(strtolower($ext), $this->allowedExtensions)) { $these = implode(', ', $this->allowedExtensions); return array('error' => 'File has an invalid extension, it should be one of ' . $these . '.'); } if (!$replaceOldFile) { /// don't overwrite previous files that were uploaded while (file_exists($uploadDirectory . $filename . '.' . $ext)) { $filename .= rand(10, 99); } } if ($this->file->save($uploadDirectory . $filename . '.' . $ext)) { $image = new SimpleImage(); $image->load($folder . $filename . '.' . $ext); $width = $image->getWidth(); $height = $image->getHeight(); $image->resize(150, 150); $image->save('uploads/thumbs/' . $filename . '-thumb.' . $ext); return array('success' => true, 'size' => $size, 'width' => $width, 'height' => $height, 'extension' => $ext, 'file_name' => $filename); } else { return array('error' => 'Could not save uploaded file.' . 'The upload was cancelled, or server error encountered'); } }
$params = UploadFileCURL::getParamsPostUrl($_POST['data']); $remote_file = $_FILES['file']; if (!empty($params['path_img_thumb']) && !empty($params['path_img_larger'])) { $path_img_larger = $params['system'] . '/' . $params['path_img_larger']; UploadFileCURL::CreatePathPermission($path_img_larger); $path_img_thumb = $params['system'] . '/' . $params['path_img_thumb']; UploadFileCURL::CreatePathPermission($path_img_thumb); } elseif (!empty($params['path'])) { $path = $params['system'] . '/' . $params['path']; UploadFileCURL::CreatePathPermission($path); } foreach ($remote_file['name'] as $key => $value) { $file = array('name' => $value, 'type' => $remote_file['type'][$key], 'tmp_name' => $remote_file['tmp_name'][$key], 'error' => $remote_file['error'][$key], 'size' => $remote_file['size'][$key]); if ($remote_file['type'][$key] == 'image/jpeg' || $remote_file['type'][$key] == 'image/png') { UploadFileCURL::upload($path_img_larger, $file); $img_larger = $path_img_larger . UploadFileCURL::getNameFile(); $img_thumb = $path_img_thumb . UploadFileCURL::getNameFile(); $params['file'][] = array('img_larger' => $img_larger, 'img_thumb' => $img_thumb); if (!empty($params['thumb_width']) && !empty($params['thumb_heigth'])) { $simpleImage = new SimpleImage(); $simpleImage->load($img_larger); $simpleImage->resize($params['thumb_width'], $params['thumb_heigth']); $simpleImage->save($img_thumb); } } else { UploadFileCURL::upload($path, $file); $file_path = $path . UploadFileCURL::getNameFile(); $params['file'][] = array('file_path' => $file_path); } } echo json_encode($params);
$photo =time().$_FILES['photo'.$v]['name']; $_POST['p_color']; mysql_query("INSERT INTO tbl_img(user_id,product_id,product_img) VALUES('$user_id','$product_id','$p_color')"); } */ } else { echo 'error in adding'; } if ($_FILES['sign']['name'] != '') { //include('SimpleImage.php'); $target_path = 'uploads/'; $target_path = $target_path . basename(time() . $_FILES['sign']['name']); if (move_uploaded_file($_FILES['sign']['tmp_name'], $target_path)) { $sign = time() . $_FILES['sign']['name']; $image1 = new SimpleImage(); $image1->load("uploads/" . $sign); $image1->resize(200, 100); $image1->save("uploads/thumb/" . $sign); } /*for($v=1;$v<=5; $v++){ $photo =time().$_FILES['photo'.$v]['name']; $_POST['p_color']; mysql_query("INSERT INTO tbl_img(user_id,product_id,product_img) VALUES('$user_id','$product_id','$p_color')"); } */ } else { echo 'error in adding'; } mysql_query("INSERT INTO membership( name, address,Telephone,Residenace,representative,doe,Category,mem_type,Business,Products,Proposed,Seconded,Place,date,sign1_id,sign2_id,sign_id) VALUES('{$name}','{$address}','{$Telephone}','{$Residenace}','{$representative}','{$doe}','{$Category}','{$mem_type}','{$Business}','{$Products}','{$Proposed}','{$Seconded}','{$Place}','{$date}','{$sign1}','{$sign2}','{$sign}')"); echo "<script language='javascript'> window.location='apply_mem.php'; </script>"; exit; } ?>
public function cropPhoto() { $my = JFactory::getUser(); $ajax = DiscussHelper::getHelper('Ajax'); if (!$my->id) { $ajax->reject(JText::_('You are not allowed here')); return $ajax->send(); } $config = DiscussHelper::getConfig(); $profile = DiscussHelper::getTable('Profile'); $profile->load($my->id); $path = rtrim($config->get('main_avatarpath'), DIRECTORY_SEPARATOR); $path = JPATH_ROOT . '/' . $path; $photoPath = $path . '/' . $profile->avatar; $originalPath = $path . '/' . 'original_' . $profile->avatar; // @rule: Delete existing image first. if (JFile::exists($photoPath)) { JFile::delete($photoPath); } $x1 = JRequest::getInt('x1'); $y1 = JRequest::getInt('y1'); $width = JRequest::getInt('width'); $height = JRequest::getInt('height'); if (is_null($x1) && is_null($y1) && is_null($width) && is_null($height)) { $ajax->reject(JText::_('Unable to crop because cropping parameters are incomplete!')); return $ajax->send(); } require_once DISCUSS_CLASSES . '/simpleimage.php'; $image = new SimpleImage(); $image->load($originalPath); $image->crop($width, $height, $x1, $y1); $image->resize(160, 160); $image->save($photoPath); $path = trim($config->get('main_avatarpath'), '/') . '/' . $profile->avatar; $uri = rtrim(JURI::root(), '/'); $uri .= '/' . $path; $ajax->resolve($uri, 'Avatar cropped successfully!'); return $ajax->send(); }
$s1 = 1; if (!$res) { error('File Type not allowed!! You can only upload JPEG,PNG,BMP and GIF images.'); $s1 = 0; } $name = str_replace(' ', '_', $name); $name = get_rand_id(15) . '_' . $name; $target = $target . $name; $mimg = kbase() . '/kart/' . $target; $timg = kbase() . '/kart/' . "itemimage/thumb_" . $name; if (move_uploaded_file($_FILES['mimg']['tmp_name'], $target)) { $s2 = 1; $path = "itemimage/thumb_" . $name; $image = new SimpleImage(); $image->load($target); $image->resize(150, 100); $image->save($path); delete($_POST['mimg']); delete($_POST['timg']); } else { error('Error Uploading Main Image !!'); $s2 = 0; } } else { $mimg = $_POST['mimg']; $timg = $_POST['timg']; $s1 = 1; $s2 = 1; } // ***************************** Image 2 ******************** if (basename($_FILES['img1']['name'])) {
function uploadPicture() { //Standard Werte definieren define('MAX_SIZE', "3145728"); // Maximal 3MB define('UPLOAD_DIR', "upload/images/"); //Ordner in dem die Bilder gespeichert werden //Bildwerte abfangen und speichern $bild_name = $_FILES['bild']['name']; $bild_tmp = $_FILES['bild']['tmp_name']; $bild_size = $_FILES['bild']['size']; $bild_type = $_FILES['bild']['type']; //Allfällige Punkte aus String löschen damit extension richtig festgestellt wird $bild_name = deletePoints($bild_name); $bild_ext = strtolower(substr($bild_name, strpos($bild_name, ".") + 1)); //toLower um beim überprüfen keine Probleme zu haben //Überprüfen ob Datei nicht leer ist und keine Fehler hat if (!empty($_FILES['bild']) && $_FILES['bild']['error'] == 0) { if (!($bild_ext == "jpg" || $bild_ext == "jpeg" || $bild_ext == "gif" || $bild_ext == "png")) { //Datei-Typ ist nicht korrekt return false; } if ($bild_size > MAX_SIZE) { //Datei ist zu gross return false; } } else { //Keine oder fehlerhafte Datei return false; } //Alle Vorgaben korrekt if (!isset($message)) { //Pfad für Datei welche auf Server liegen wird und in DB gespeichert wird $bild_location = UPLOAD_DIR . $bild_name; //Datei auf den Server kopieren move_uploaded_file($bild_tmp, $bild_location); $sizes = getimagesize($bild_location); $width = $sizes[0]; $height = $sizes[1]; //Falls die Grösse nicht der vorgegebenen entspricht if ($width != "1280" && $height != "768") { //Bild mit Hilfe der SimpleImage Klasse auf die benötigte grösse 1280x768px anpassen include 'includes/simpleImage.php'; $image = new SimpleImage(); $image->load($bild_location); $image->resize(1280, 768); $image->save($bild_location); $_SESSION['bild_resize'] = true; //Upload Ordner in Session speichern, um später für DB Query wieder abfragen zu können $_SESSION['bild_location'] = $bild_location; unlink($temp_bild_location); } else { $_SESSION['bild_resize'] = false; //Upload Ordner in Session speichern, um später für DB Query wieder abfragen zu können $_SESSION['bild_location'] = $bild_location; } //Bildupload erfolgreich return true; } else { //Bildupload fehlgeschlagen return false; } }
function create_thumbs($key = false) { if ($this->type == 'private' || $this->access == 'private') { return false; } $pathname = $this->pathname(); if (!file_exists($pathname)) { if (!$this->restore()) { return false; } } require_once mnminclude . "simpleimage.php"; $thumb = new SimpleImage(); $thumb->load($pathname); if (!$thumb->load($pathname)) { $alternate_image = mnmpath . "/img/common/picture02.png"; syslog(LOG_INFO, "Meneame, trying alternate thumb ({$alternate_image}) for {$pathname}"); if (!$thumb->load($alternate_image)) { return false; } } $res = 0; foreach (Upload::thumb_sizes() as $k => $s) { if ($key && $key != $k) { continue; } // Generated just what was requested $thumb->resize($s, $s, true); if ($thumb->save($this->thumb_pathname($k))) { $res++; @chmod($this->thumb_pathname($k), 0777); $this->thumb = $thumb; } } return $res; }
$i = 0; if ($visible == "on") { $i = 1; } $qry = "update images set disporder=" . $existord . " where disporder=" . $dispord; echo $qry . " "; // ExecuteNonQuery($qry); } include 'includes/SimpleImage.php'; $image1 = $_FILES["photoimage"]["name"]; $fnm = getfilename($image1); $ext1 = getExtension($image1); $dt = getdt(); $image = new SimpleImage(); $image->load($_FILES['photoimage']['tmp_name']); $image->resize(375, 375); // $t1=str_replace("_fullsize","",$fnm); $tmp = "../usrfiles/medium/" . $fnm . "_" . $dt . "_preview." . $ext1; $image->save($tmp); $tmp1 = "../usrfiles/thumb/" . $fnm . "_" . $dt . "_thumbnail." . $ext1; $image->resize(75, 75); $image->save($tmp1); move_uploaded_file($_FILES['photoimage']['tmp_name'], "../usrfiles/large/" . $fnm . "_" . $dt . "_fullsize." . $ext1); $tmp1 = $fnm . "_" . $dt . "." . $ext1; $i = 0; if ($_POST["cbvisible"] == "on") { $i = 1; } $c_date = date("Y-m-d"); $str = "update images set imagename='" . $inm . "',imagetitle='" . $tmp1 . "',visible=b'" . $i . "',modifyip='" . getip() . "',modifydate='" . $c_date . "',disporder=" . $dispord . ",imgcatid=" . $catid . " where imageid=" . $_GET["id"]; // echo $str;
public static function uploadMediaAvatar($mediaType, $mediaTable, $isFromBackend = false) { jimport('joomla.utilities.error'); jimport('joomla.filesystem.file'); jimport('joomla.filesystem.folder'); $my = JFactory::getUser(); $mainframe = JFactory::getApplication(); $config = DiscussHelper::getConfig(); //$acl = DiscussACLHelper::getRuleSet(); // required params $layout_type = $mediaType == 'category' ? 'categories' : 'teamblogs'; $view_type = $mediaType == 'category' ? 'categories' : 'teamblogs'; $default_avatar_type = $mediaType == 'category' ? 'default_category.png' : 'default_team.png'; if (!$isFromBackend && $mediaType == 'category') { $url = 'index.php?option=com_easydiscuss&view=categories'; DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_NO_PERMISSION_TO_UPLOAD_AVATAR'), 'warning'); $mainframe->redirect(DiscussRouter::_($url, false)); } $avatar_config_path = $mediaType == 'category' ? $config->get('main_categoryavatarpath') : $config->get('main_teamavatarpath'); $avatar_config_path = rtrim($avatar_config_path, '/'); $avatar_config_path = str_replace('/', DIRECTORY_SEPARATOR, $avatar_config_path); $upload_path = JPATH_ROOT . '/' . $avatar_config_path; $rel_upload_path = $avatar_config_path; $err = null; $file = JRequest::getVar('Filedata', '', 'files', 'array'); //check whether the upload folder exist or not. if not create it. if (!JFolder::exists($upload_path)) { if (!JFolder::create($upload_path)) { // Redirect if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::_('COM_EASYDISCUSS_IMAGE_UPLOADER_FAILED_TO_CREATE_UPLOAD_FOLDER'), 'error'); $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false)); } else { //from backend $this->setRedirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false), JText::_('COM_EASYDISCUSS_IMAGE_UPLOADER_FAILED_TO_CREATE_UPLOAD_FOLDER'), 'error'); } return; } else { // folder created. now copy index.html into this folder. if (!JFile::exists($upload_path . '/index.html')) { $targetFile = DISCUSS_ROOT . '/index.html'; $destFile = $upload_path . '/index.html'; if (JFile::exists($targetFile)) { JFile::copy($targetFile, $destFile); } } } } //makesafe on the file $file['name'] = $mediaTable->id . '_' . JFile::makeSafe($file['name']); if (isset($file['name'])) { $target_file_path = $upload_path; $relative_target_file = $rel_upload_path . '/' . $file['name']; $target_file = JPath::clean($target_file_path . '/' . JFile::makeSafe($file['name'])); $isNew = false; require_once DISCUSS_HELPERS . '/image.php'; require_once DISCUSS_CLASSES . '/simpleimage.php'; if (!DiscussImageHelper::canUpload($file, $err)) { if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::_($err), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false)); } else { // From backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories'), JText::_($err), 'error'); } return; } if (0 != (int) $file['error']) { if (!$isFromBackend) { DiscussHelper::setMessageQueue($file['error'], 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false)); } else { // From backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false), $file['error'], 'error'); } return; } // Rename the file 1st. $oldAvatar = empty($mediaTable->avatar) ? $default_avatar_type : $mediaTable->avatar; $tempAvatar = ''; if ($oldAvatar != $default_avatar_type) { $session = JFactory::getSession(); $sessionId = $session->getToken(); $fileExt = JFile::getExt(JPath::clean($target_file_path . '/' . $oldAvatar)); $tempAvatar = JPath::clean($target_file_path . '/' . $sessionId . '.' . $fileExt); JFile::move($target_file_path . '/' . $oldAvatar, $tempAvatar); } else { $isNew = true; } if (JFile::exists($target_file)) { if ($oldAvatar != $default_avatar_type) { //rename back to the previous one. JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar); } if (!$isFromBackend) { DiscussHelper::setMessageQueue(JText::sprintf('ERROR.FILE_ALREADY_EXISTS', $relative_target_file), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false)); } else { //from backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false), JText::sprintf('ERROR.FILE_ALREADY_EXISTS', $relative_target_file), 'error'); } return; } if (JFolder::exists($target_file)) { if ($oldAvatar != $default_avatar_type) { //rename back to the previous one. JFile::move($tempAvatar, $target_file_path . '/' . $oldAvatar); } if (!$isFromBackend) { //JError::raiseNotice(100, JText::sprintf('ERROR.FOLDER_ALREADY_EXISTS',$relative_target_file)); DiscussHelper::setMessageQueue(JText::sprintf('ERROR.FOLDER_ALREADY_EXISTS', $relative_target_file), 'error'); $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false)); } else { //from backend $mainframe->redirect(DiscussRouter::_('index.php?option=com_easydiscuss&view=categories', false), JText::sprintf('ERROR.FILE_ALREADY_EXISTS', $relative_target_file), 'error'); } return; } $configImageWidth = DISCUSS_AVATAR_LARGE_WIDTH; $configImageHeight = DISCUSS_AVATAR_LARGE_HEIGHT; $image = new SimpleImage(); $image->load($file['tmp_name']); $image->resize($configImageWidth, $configImageHeight); $image->save($target_file, $image->image_type); //now we update the user avatar. If needed, we remove the old avatar. if ($oldAvatar != $default_avatar_type) { if (JFile::exists($tempAvatar)) { JFile::delete($tempAvatar); } } return JFile::makeSafe($file['name']); } else { return $default_avatar_type; } }
<?php include 'SimpleImage.php'; ini_set("memory_limit", "50M"); $image = new SimpleImage(); $sizes = array(16, 29, 32, 36, 40, 48, 50, 57, 58, 60, 64, 72, 76, 80, 87, 96, 100, 114, 120, 128, 144, 152, 180, 192, 256, 512, 1024); foreach ($sizes as $size) { $image->load($argv[1] ? $argv[1] : 'icon.png'); $image->resize($size, $size); $image->save('icon' . $size . 'x' . $size . '.png', IMAGETYPE_PNG); } unset($size); echo "icons generated \r\n";
} } } else { if ($exitstord != $dispord) { $i = 0; if ($visible == "on") { $i = 1; } $qry = "update banners set disporder=" . $existord . " where disporder=" . $dispord; //echo $qry." "; ExecuteNonQuery($qry); } include 'includes/SimpleImage.php'; $image = new SimpleImage(); $image->load($_FILES['bannerimage']['tmp_name']); $image->resize(1024, 250); $image1 = $_FILES["bannerimage"]["name"]; $fnm = getfilename($image1); $ext1 = getExtension($image1); $dt = getdt(); $tmp = "../banners/large/" . $fnm . "_" . $dt . "." . $ext1; $image->save($tmp); $tmp1 = "../banners/thumb/" . $fnm . "_" . $dt . "." . $ext1; $image->resize(240, 55); $image->save($tmp1); $tmp1 = $fnm . "_" . $dt . "." . $ext1; $i = 0; if ($_POST["cbvisible"] == "on") { $i = 1; } $c_date = date("Y-m-d");
function thumbnail($zmd5 = null) { $sitename = $_GET["thumbnail"]; $width = $_GET["width"]; $q = new mysql_squid_builder(); $familySite = $q->GetFamilySites($sitename); $md = md5($sitename); $md_family = md5($familySite); if ($zmd5 != null) { $md = $zmd5; } if (isset($_GET["zmd5"])) { $md = $_GET["zmd5"]; } if (!is_numeric($width)) { $width = 400; } $imagepath = "ressources/logs/thumbnails.{$md}.{$width}.gif"; $imageSourcePath = "ressources/logs/thumbnails.{$md}.400.gif"; if ($GLOBALS["VERBOSE"]) { echo "<H1>VERBOSES {$sitename}/{$familySite} - {$md} -</H1>"; if (is_file($imageSourcePath)) { echo "<li>{$md} {$imageSourcePath} exists on disk</li>"; echo "<li>{$imageSourcePath} file_md5=" . md5_file($imageSourcePath) . "</li>"; } } $badThumbs["ee1e683b39c902e5ee69fadcff54b6b9"] = true; $badThumbs["45ec39db5951e8e11be11f5148bd707a"] = true; if (is_file($imageSourcePath)) { $md5_file = md5_file($imageSourcePath); } if ($badThumbs[$md5_file]) { if ($GLOBALS["VERBOSE"]) { echo "<li style=color:#d32d2d>Deleting {$md}</li>"; } @unlink($imageSourcePath); @unlink($imagepath); $q->QUERY_SQL("DELETE FROM webfilters_thumbnails WHERE zmd5='{$md}'"); $q->QUERY_SQL("DELETE FROM webfilters_thumbnails WHERE LinkTo='{$md}'"); } if (is_file($imagepath)) { if (!$GLOBALS["VERBOSE"]) { header("Content-type: image/gif"); ob_clean(); flush(); readfile($imagepath); } return; } else { if ($GLOBALS["VERBOSE"]) { echo "<li>{$imagepath} no such file</li>"; } } if (!is_file($imageSourcePath)) { $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT savedate,filemd5,picture,LinkTo FROM webfilters_thumbnails WHERE zmd5='{$md}'")); if ($GLOBALS["VERBOSE"]) { echo "<li>{$md} LinkTo={$ligne["LinkTo"]} - " . strlen($ligne["picture"]) . " bytes</li>"; } if (trim($ligne["LinkTo"]) != null) { thumbnail($ligne["LinkTo"]); return; } if ($ligne["picture"] == null) { if ($md_family != $md) { thumbnail($md_family); return; } } if ($ligne["picture"] != null) { @file_put_contents($imageSourcePath, $ligne["picture"]); } } else { if ($GLOBALS["VERBOSE"]) { echo "<li>{$md} {$imageSourcePath} exists on disk</li>"; } if ($GLOBALS["VERBOSE"]) { echo "<li>{$imageSourcePath} file_md5=" . md5_file($imageSourcePath) . "</li>"; } } if (is_file($imageSourcePath)) { if ($width < 400) { if ($GLOBALS["VERBOSE"]) { echo "<li>{$md} ->SimpleImage({$imageSourcePath})</li>"; } $image = new SimpleImage(); $image->load($imageSourcePath); if ($GLOBALS["VERBOSE"]) { echo "<li>{$md} ->resize({$width},{$width})</li>"; } $image->resize($width, $width); $image->save($imagepath); if (!$GLOBALS["VERBOSE"]) { header("Content-type: image/gif"); ob_clean(); flush(); readfile($imagepath); } return; } if (!$GLOBALS["VERBOSE"]) { header("Content-type: image/gif"); ob_clean(); flush(); readfile($imageSourcePath); } return; } if (!is_file($imageSourcePath)) { if ($width < 400) { if (!is_file("img/bgheader-{$width}-thumbs-400.gif")) { $image = new SimpleImage(); $image->load("img/bgheader--thumbs-400.gif"); $image->resize($width, $width); $image->save("img/bgheader-{$width}-thumbs-400.gif"); } header("Content-type: image/gif"); ob_clean(); flush(); readfile("img/bgheader-{$width}-thumbs-400.gif"); return; } header("Content-type: image/gif"); ob_clean(); flush(); readfile("img/bgheader--thumbs-400.gif"); return; } }
<?php include_once("simpleimage.php"); $path = $_GET["image"]; $w = 60; $h = 60; if ( isset($_GET["w"]) ) $w=intval($_GET["w"]); if ( isset($_GET["h"]) ) $h=intval($_GET["h"]); if ( !file_exists($path) ) $path = "noimage.jpg"; $im = new SimpleImage(); $im->load($path); $im->resize($w,$h); header("Content-type: image/jpeg"); imagejpeg($im->image); ?>
function resizeImage($imagePath, $width, $height) { global $module; $folderPath = $this->resize_folder; if (!JFolder::exists($folderPath)) { JFolder::create($folderPath); } $nameImg = str_replace('/', '', strrchr($imagePath, "/")); $ext = substr($nameImg, strrpos($nameImg, '.')); $file_name = substr($nameImg, 0, strrpos($nameImg, '.')); $size = getimagesize($imagePath); // if it's not a image. if (!$size) { return ''; } // case 1: render image base on the ratio of source. $x_ratio = $width / $size[0]; $y_ratio = $height / $size[1]; // set dst, src $dst = new stdClass(); $src = new stdClass(); $src->y = $src->x = 0; $dst->y = $dst->x = 0; if ($width > $size[0]) { $width = $size[0]; } if ($height > $size[1]) { $height = $size[1]; } $nameImg = $file_name . "_" . $width . "_" . $height . $ext; if (!JFile::exists($folderPath . DS . $nameImg)) { $image = new SimpleImage(); $image->load($imagePath); $image->resize($width, $height); $image->save($folderPath . DS . $nameImg); } else { list($info_width, $info_height) = @getimagesize($folderPath . DS . $nameImg); if ($width != $info_width || $height != $info_height) { $image = new SimpleImage(); $image->load($imagePath); $image->resize($width, $height); $image->save($folderPath . DS . $nameImg); } } return $this->url_to_resize . $nameImg; }
function resizeImage($imagePath, $width, $height) { global $module; $folderPath = $this->resize_folder; if(!JFolder::exists($folderPath)){ JFolder::create($folderPath); } $nameImg = str_replace('/','',strrchr($imagePath,"/")); $ext = substr($nameImg, strrpos($nameImg, '.')); $file_name = substr($nameImg, 0, strrpos($nameImg, '.')); $nameImg = str_replace(" ","",$file_name . "_" . $width . "_" . $height . $ext); if(!JFile::exists($folderPath.DS.$nameImg)){ $image = new SimpleImage(); $image->load($imagePath); $image->resize($width,$height); $image->save($folderPath.DS.$nameImg); }else{ list($info_width, $info_height) = @getimagesize($folderPath.DS.$nameImg); if($width!=$info_width||$height!=$info_height){ $image = new SimpleImage(); $image->load($imagePath); $image->resize($width,$height); $image->save($folderPath.DS.$nameImg); } } return $this->url_to_resize . $nameImg; }
exit;*/ if ($folder = opendir($dir)) { while (($file = readdir($folder)) !== false) { $source_file = $dir . $file; if (stristr($source_file, ".jpg") || stristr($source_file, ".gif")) { $i++; if ($i <= 10) { $xpld = ""; $xpld = explode('_', $file); if (strlen($xpld[0])) { mysql_query("update gns_propdetail SET images=concat(images,'~','" . str_replace($xpld[0] . "_", "", $file) . "','~') WHERE propid='{$xpld['0']}'"); $file = str_replace('_', '-', $file); $image = new SimpleImage(); $image->load($source_file); $image->resize(100, 100); $image->save("../../propertyphoto/thumb/" . $file); list($width, $height) = getimagesize($source_file); if ($height > 600 || $width > 800) { $image->load($source_file); $image->resize(800, 600); $image->save("../../propertyphoto/" . $file); } //copy($source_file,"../../propertyphoto/".$file); echo $source_file . "<br>"; unlink($source_file); //exit; } } else { echo "<script>window.location.href='?';</script>"; }
public function executeAvatar(sfWebRequest $request) { $this->form = new UploadAvatarForm(); $user = PcUserPeer::getLoggedInUser(); $this->isUploaded = false; if ($request->isMethod('post')) { $this->form->bind($request->getParameter('avatar'), $request->getFiles('avatar')); if ($this->form->isValid()) { $file = $this->form->getValue('file'); $extension = $file->getExtension($file->getOriginalExtension()); $filenameWithNoRandomNorExtension = $user->getForumId() . '_'; if ($file->getSize() > sfConfig::get('app_avatar_maxSize')) { die(__('ACCOUNT_SETTINGS_AVATAR_TOO_BIG')); } $random = PcUtils::generate32CharacterRandomHash(); // see generate_avatar_markup PunBB function $fileFullPathWithNoRandomNorExtension = sfConfig::get('sf_web_dir') . '/' . sfConfig::get('app_avatar_relativeRoot') . '/' . $filenameWithNoRandomNorExtension; $fileFullPath = $fileFullPathWithNoRandomNorExtension . $random . $extension; $fileFullPathWildcard = $fileFullPathWithNoRandomNorExtension . '*.*'; // {{{ deleting pre-existing files $filesToDelete = glob($fileFullPathWildcard); foreach ($filesToDelete as $fileToDelete) { unlink($fileToDelete); } /// }}} $file->save($fileFullPath); $user->setAvatarRandomSuffix($random)->save(); // resizing $image = new SimpleImage(); $image_info = getimagesize($fileFullPath); $image->load($fileFullPath); $image->resize(sfConfig::get('app_avatar_width'), sfConfig::get('app_avatar_height')); $image->save($fileFullPath, $image_info[2], 96); $this->isUploaded = true; } } $this->hasAvatar = $user->hasAvatar(); $this->avatarUrl = $user->getAvatarUrl(); }
echo $user_language['no_file_chosen'] . ' - <a href="/user/settings">' . $general_language['back'] . '</a>'; die; } if (file_exists("avatars/" . $user->data()->id . ".jpg")) { unlink("avatars/" . $user->data()->id . ".jpg"); } else { if (file_exists("avatars/" . $user->data()->id . ".png")) { unlink("avatars/" . $user->data()->id . ".png"); } else { if (file_exists("avatars/" . $user->data()->id . ".gif")) { unlink("avatars/" . $user->data()->id . ".gif"); } } } $image->load($_FILES['uploaded_avatar']['tmp_name']); $image->resize('100', '100'); $image->save("avatars/" . $user->data()->id); $queries->update("users", $user->data()->id, array("has_avatar" => 1)); Redirect::to('/user/settings'); die; } else { // TODO echo $admin_language['invalid_token'] . ' - <a href="/user/settings">' . $general_language['back'] . '</a>'; die; } } else { // TODO Redirect::to('/user/settings'); die; } } else {
function resizeImage($imagePath, $width, $height) { global $module; $folderPath = $this->resize_folder; $parent_path = str_replace("/images/resize","",$folderPath); $parent_path = str_replace("\\images\\resize","",$parent_path); if(!JFolder::exists($parent_path)){ if(mkdir($parent_path, 0777)){ } else { echo "Error: Can't create folder for resize image!"; exit(); } } $parent_path = str_replace("/resize","",$folderPath); $parent_path = str_replace("\\resize","",$parent_path); if(!JFolder::exists($parent_path)){ //if(JFolder::create($folderPath)){echo "ok";} else {echo "not ok";} if(mkdir($parent_path, 0777)){ if(mkdir($folderPath, 0777)){ } else { echo "Error: Can't create folder for resize image!"; } } else { echo "Error: Can't create folder for resize image!"; } } else { if(!JFolder::exists($folderPath)){ if(mkdir($folderPath, 0777)){ } else { echo "Error: Can't create folder for resize image!"; } } } $nameImg = str_replace('/','',strrchr($imagePath,"/")); $ext = substr($nameImg, strrpos($nameImg, '.')); $file_name = substr($nameImg, 0, strrpos($nameImg, '.')); $nameImg = str_replace(" ","",$file_name . "_" . $width . "_" . $height . $ext); if(!JFile::exists($folderPath.DS.$nameImg)){ $image = new SimpleImage(); $image->load($imagePath); $image->resize($width,$height); $image->save($folderPath.DS.$nameImg); }else{ list($info_width, $info_height) = @getimagesize($folderPath.DS.$nameImg); if($width!=$info_width||$height!=$info_height){ $image = new SimpleImage(); $image->load($imagePath); $image->resize($width,$height); $image->save($folderPath.DS.$nameImg); } } return $this->url_to_resize . $nameImg; }
if(!move_uploaded_file($_FILES['file']['tmp_name'],'upload/'.$fileName1)) { } else { list($width, $height, $type, $attr) = getimagesize('upload/'.$fileName1); if($width>712) { $image_re = new SimpleImage(); $image_re->load('upload/'.$fileName1); $imgw = 712; $imgh = ($height * $imgw)/$width; $image_re->resize($imgw, $imgh); $image_re->save('upload/'.$fileName1); } //$insert_data="insert into member_photo_gallery(id,member_id,photo)values(NULL,'".$_SESSION['id']."','".$_FILES["file"]["name"]."')"; //$db_insert=$obj->insert($insert_data); /*$update_data="update tbl_slider set image='".$fileName1."' where id='".$db_insert."'"; $oj->edit($update_data);*/ } unset($_FILES); } else { }