public function resize($filename, $width, $height) { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return HTTPS_CATALOG . 'image/' . $new_image; } else { return HTTP_CATALOG . 'image/' . $new_image; } }
/** * Generic thumbnail code; returns HTML rather than adding * a block since thumbs tend to go inside blocks... * * @param Image $image * @return string */ public function build_thumb_html(Image $image) { global $config; $i_id = (int) $image->id; $h_view_link = make_link('post/view/' . $i_id); $h_thumb_link = $image->get_thumb_link(); $h_tip = html_escape($image->get_tooltip()); $h_tags = strtolower($image->get_tag_list()); $extArr = array_flip(array('swf', 'svg', 'mp3')); //List of thumbless filetypes if (!isset($extArr[$image->ext])) { $tsize = get_thumbnail_size($image->width, $image->height); } else { //Use max thumbnail size if using thumbless filetype $tsize = get_thumbnail_size($config->get_int('thumb_width'), $config->get_int('thumb_height')); } $custom_classes = ""; if (class_exists("Relationships")) { if (property_exists($image, 'parent_id') && $image->parent_id !== NULL) { $custom_classes .= "shm-thumb-has_parent "; } if (property_exists($image, 'has_children') && $image->has_children == TRUE) { $custom_classes .= "shm-thumb-has_child "; } } return "<a href='{$h_view_link}' class='thumb shm-thumb shm-thumb-link {$custom_classes}' data-tags='{$h_tags}' data-post-id='{$i_id}'>" . "<img id='thumb_{$i_id}' title='{$h_tip}' alt='{$h_tip}' height='{$tsize[1]}' width='{$tsize[0]}' src='{$h_thumb_link}'>" . "</a>\n"; }
protected function afterSave() { parent::afterSave(); require_once 'Image.php'; // 保存图片 if ($this->bannerFile instanceof CUploadedFile && $this->hasErrors('bannerFile') == false) { // 保存原文件 $file = $this->bannerFile; $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName; //list($width, $height, $type, $attr) = getimagesize($file->tempName); $filePath = Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND); $file->saveAs($filePath); if (strtolower($file->extensionName) != 'swf') { $image = new Image($filePath); $image->save(Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND)); } // 更新数据 $this->updateByPk($this->primaryKey, array('banner_path' => $fileName)); } else { if ($this->deleteBannerFile) { // 删除图片 @unlink(Helper::mediaPath(self::UPLOAD_LARGE_IMAGE_PATH . $this->banner_path, FRONTEND)); // 更新数据 $this->updateByPk($this->primaryKey, array('banner_path' => '')); } } }
public function createImageKey($user, $dblink) { if ($stm = $dblink->prepare("SELECT 2fa_imgname FROM " . TABLE_USERS . " WHERE email = ?")) { $stm->execute(array($user)); $row = $stm->fetch(); $stm = NULL; $file = 'uploads/2fa/' . $row['2fa_imgname']; } $im = new Image(); $imageclean = $im->loadLocalFile($file); $imagekey = $im->embedStegoKey($imageclean); $stegoKey = $im->stegoKey; $hash = password_hash($stegoKey, PASSWORD_DEFAULT); if ($stm = $dblink->prepare("UPDATE " . TABLE_USERS . " SET 2fa_hash = ? WHERE email = ?")) { $stm->execute(array($hash, $user)); $stm = NULL; } if (ob_get_level()) { ob_end_clean(); } header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=KeyImage.png'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); //header('Content-Length: ' . filesize($file)); $ok = imagepng($imagekey); //, NULL, 9 imagedestroy($imagekey); return $ok; }
/** * * @param filename string * @param width * @param height * @param type char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($filename, $width, $height, $type = "") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } return $this->getImageUrl($new_image); }
public function generate_thumb() { $image = new Image($this->get_image_path()); $image->resize(200, 200); $image->save($this->get_thumb_path()); return TRUE; }
public function confirm() { /** * 確認画面用 * */ //バリデーションエラー include_once 'Validate.php'; $validate = new Validate(); //画像用のプラグイン発動 include_once 'Image.php'; $file = new Image(); //まずは、POSTされたデータを取得 $requestData = $_POST; /** * 画像ファイルの加工 * */ $requestData['file1'] = $file->set_url('file1'); $requestData['file2'] = $file->set_url('file2'); $requestData['file3'] = $file->set_url('file3'); unset($requestData['ContactForm']); //変数へセットする $this->set('requestData', $requestData); }
function Thumb($img, $width = '', $height = '') { $thumb_img = 'Public/thumb.jpg'; if ($img) { $img = substr($img, 1); $is_img = GetImageSize('./' . $img); //设置宽高 生成缩略图 if (!empty($width) && !empty($height)) { import('ORG.Util.Image'); $Image = new Image(); $filename = 'Uploads/thumb/' . $width . '_' . $height . '/'; //缩略图存储路径 $new_name = strtr($img, array('/' => '_')); if (!file_exists($filename)) { @mkdir($filename, 0755); } if ($is_img) { $is_thumb = GetImageSize('./' . $filename . $new_name); if ($is_thumb) { $thumb_img = $filename . $new_name; } else { $Image->thumb($img, $filename . $new_name, '', $width, $height); $thumb_img = $filename . $new_name; } } } else { if ($is_img) { $thumb_img = $img; } } } return '/' . $thumb_img; }
public function post_instagram() { // fetch input data $input = Input::all(); // create rules for validator $rules = array('image' => 'required|unique:images', 'description' => 'required|max:100'); // validate the data with set rules $v = Validator::make($input, $rules); if ($v->fails()) { // if validation fails, redirect back with relevant error messages return Redirect::back()->withErrors($v); } else { // store image info in the database $image = Input::all('image'); $img = new Image(); $img->description = Input::get('description'); $img->image = $image['image']; $img->user_id = Auth::user()->id; $img->approved = "0"; $saveflag = $img->save(); if ($saveflag) { return Redirect::back()->withErrors('Upload Successful!'); } } }
public function display_image(Page $page, Image $image) { global $config; $u_ilink = $image->get_image_link(); if ($config->get_bool("image_show_meta") && function_exists("exif_read_data")) { # FIXME: only read from jpegs? $exif = @exif_read_data($image->get_image_filename(), 0, true); if ($exif) { $head = ""; foreach ($exif as $key => $section) { foreach ($section as $name => $val) { if ($key == "IFD0") { // Cheap fix for array'd values in EXIF-data if (is_array($val)) { $val = implode(',', $val); } $head .= html_escape("{$name}: {$val}") . "<br>\n"; } } } if ($head) { $page->add_block(new Block("EXIF Info", $head, "left")); } } } $html = "<img alt='main image' class='shm-main-image' id='main_image' src='{$u_ilink}' " . "data-width='{$image->width}' data-height='{$image->height}'>"; $page->add_block(new Block("Image", $html, "main", 10)); }
protected function afterSave() { parent::afterSave(); $this->validateBannerFile('bannerFile', null); require_once 'Image.php'; // 保存图片 if ($this->hasErrors('bannerFile') == false && $this->bannerFile instanceof CUploadedFile) { // 保存原图 $file = $this->bannerFile; $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName; $filePath = Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND); $file->saveAs($filePath); // 如果是图片需要进行裁切 // 右侧底图 if (strtolower($file->extensionName) != 'swf') { $image = new Image($filePath); $image->save(Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $fileName, FRONTEND)); } // 更新数据 $this->updateByPk($this->primaryKey, array('banner_path' => $fileName)); } else { if ($this->deleteBannerFile) { @unlink(Helper::mediaPath(Banner::UPLOAD_LARGE_IMAGE_PATH . $this->banner_path, FRONTEND)); // 更新数据 $this->updateByPk($this->primaryKey, array('banner_path' => '')); } } }
private function build_stats(Image $image) { $h_owner = html_escape($image->get_owner()->name); $h_ownerlink = "<a href='" . make_link("user/{$h_owner}") . "'>{$h_owner}</a>"; $h_ip = html_escape($image->owner_ip); $h_date = autodate($image->posted); $h_filesize = to_shorthand_int($image->filesize); global $user; if ($user->can("view_ip")) { $h_ownerlink .= " ({$h_ip})"; } $html = "\n\t\tId: {$image->id}\n\t\t<br>Posted: {$h_date} by {$h_ownerlink}\n\t\t<br>Size: {$image->width}x{$image->height}\n\t\t<br>Filesize: {$h_filesize}\n\t\t"; if (!is_null($image->source)) { $h_source = html_escape($image->source); if (substr($image->source, 0, 7) != "http://" && substr($image->source, 0, 8) != "https://") { $h_source = "http://" . $h_source; } $html .= "<br>Source: <a href='{$h_source}'>link</a>"; } if (class_exists("Ratings")) { if ($image->rating == null || $image->rating == "u") { $image->rating = "u"; } $h_rating = Ratings::rating_to_human($image->rating); $html .= "<br>Rating: {$h_rating}"; } return $html; }
/** * * @param filename string * @param width * @param height * @param type char [default, w, h] * default = scale with white space, * w = fill according to width, * h = fill according to height * */ public function resize($filename, $width, $height, $type = "") { if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) { return; } $info = pathinfo($filename); $extension = $info['extension']; $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type . '.' . $extension; if (!file_exists(DIR_IMAGE . $new_image) || filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!file_exists(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height, $type); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1')) { return (defined('HTTPS_STATIC_CDN') ? HTTPS_STATIC_CDN : $this->config->get('config_ssl')) . 'image/' . $new_image; } else { return (defined('HTTP_STATIC_CDN') ? HTTP_STATIC_CDN : $this->config->get('config_url')) . 'image/' . $new_image; } }
public static function genImgForSlider($apartmentId) { $mainImage = Images::getMainImageData(null, $apartmentId); if ($mainImage) { $imgName = $mainImage['file_name']; Yii::import('application.extensions.image.Image'); $pathImg = DIRECTORY_SEPARATOR . Images::UPLOAD_DIR . DIRECTORY_SEPARATOR . Images::OBJECTS_DIR . DIRECTORY_SEPARATOR . $apartmentId . DIRECTORY_SEPARATOR . Images::ORIGINAL_IMG_DIR . DIRECTORY_SEPARATOR . $imgName; $sliderDir = DIRECTORY_SEPARATOR . Images::UPLOAD_DIR . DIRECTORY_SEPARATOR . Images::OBJECTS_DIR . DIRECTORY_SEPARATOR . $apartmentId . DIRECTORY_SEPARATOR . Images::MODIFIED_IMG_DIR . DIRECTORY_SEPARATOR; if ($mainImage['file_name_modified']) { $name = $mainImage['file_name_modified']; } else { $name = Images::updateModifiedName($mainImage); } $sliderImgName = 'thumb_' . param('slider_img_width', 500) . 'x' . param('slider_img_height', 280) . '_' . $name; $pathImgSlider = $sliderDir . DIRECTORY_SEPARATOR . $sliderImgName; if (!is_dir(ROOT_PATH . $sliderDir)) { @mkdir(ROOT_PATH . $sliderDir); } @unlink(ROOT_PATH . $pathImgSlider); if (!file_exists(ROOT_PATH . $pathImgSlider)) { $image = new Image(ROOT_PATH . $pathImg); $image->resizeWithEffect(param('slider_img_width', 500), param('slider_img_height', 280)); $image->save(ROOT_PATH . $pathImgSlider); return true; } else { return true; } } return false; }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename) || substr(str_replace('\\', '/', realpath(DIR_IMAGE . $filename)), 0, strlen(DIR_IMAGE)) != DIR_IMAGE) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . (int) $width . 'x' . (int) $height . '.' . $extension; if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname($new_image)); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } $new_image = str_replace(' ', '%20', $new_image); if (isset($this->request->server['HTTPS']) && ($this->request->server['HTTPS'] == 'on' || $this->request->server['HTTPS'] == '1') || $this->request->server['HTTPS'] == '443') { return $this->config->get('config_ssl') . 'image/' . $new_image; } elseif (isset($this->request->server['HTTP_X_FORWARDED_PROTO']) && $this->request->server['HTTP_X_FORWARDED_PROTO'] == 'https') { return $this->config->get('config_ssl') . 'image/' . $new_image; } else { return $this->config->get('config_url') . 'image/' . $new_image; } }
public function display_image(Page $page, Image $image) { $ilink = $image->get_image_link(); // FIXME: object and embed have "height" and "width" $html = "\n\t\t\t<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'\n\t\t\t codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'\n\t\t\t\t\theight='{$image->height}'\n\t\t\t\t\twidth='{$image->width}'\n\t\t\t\t\twmode='opaque'\n\t\t\t\t\t>\n\t\t\t\t<param name='movie' value='{$ilink}'/>\n\t\t\t\t<param name='quality' value='high' />\n\t\t\t\t<embed src='{$ilink}' quality='high'\n\t\t\t\t\tpluginspage='http://www.macromedia.com/go/getflashplayer'\n\t\t\t\t\theight='{$image->height}'\n\t\t\t\t\twidth='{$image->width}'\n\t\t\t\t\twmode='opaque'\n\t\t\t\t\ttype='application/x-shockwave-flash'></embed>\n\t\t\t</object>"; $page->add_block(new Block("Flash Animation", $html, "main", 10)); }
public function avatar() { $uid = $this->request->get('uid'); $size = $this->request->get('s'); if (!is_numeric($uid)) { Typecho_Common::error(404); exit; } $path = __TYPECHO_ROOT_DIR__ . Widget_Common::getAvatarPath($uid); $path .= $uid . '.jpg'; if (!is_file($path)) { $path = __TYPECHO_ROOT_DIR__ . '/usr/avatar/default.jpg'; } require_once __TYPECHO_ROOT_DIR__ . '/var/Util/Image.php'; $image = new Image(); $image->open($path); $type = $image->type(); if (is_numeric($size)) { $image->thumb($size, $size); } header('Content-Type:image/' . $type . ';'); //输出图像 if ('jpeg' == $type || 'jpg' == $type) { // 采用jpeg方式输出 imagejpeg($image->showImg()); } elseif ('gif' == $type) { imagegif($image->showImg()); } else { $fun = 'image' . $type; $fun($image->showImg()); } }
public function process(Image $image) { $destCanvas = $image->getCanvas(); $destImageMetrics = $image->getMetrics(); $watermarkImage = $this->getWaterMarkSource(); $wmWidth = $this->watermarkMetrics[0]; $wmHeight = $this->watermarkMetrics[1]; $wmImageType = $this->watermarkMetrics[2]; $destinationX = ""; $destinationY = ""; switch ($this->position) { case self::TOP_LEFT: $destinationX = $destImageMetrics->sourceWidth - $destImageMetrics->sourceWidth; $destinationY = $destImageMetrics->sourceHeight - $destImageMetrics->sourceHeight; break; case self::TOP_RIGHT: $destinationX = $destImageMetrics->sourceWidth - $wmWidth - 15; $destinationY = $destImageMetrics->sourceHeight - $destImageMetrics->sourceHeight; break; case self::BOTTOM_LEFT: $destinationX = $destImageMetrics->sourceWidth - $destImageMetrics->sourceWidth; $destinationY = $destImageMetrics->sourceHeight - $wmHeight - 15; break; case self::BOTTOM_RIGHT: $destinationX = $destImageMetrics->sourceWidth - $wmWidth - 15; $destinationY = $destImageMetrics->sourceHeight - $wmHeight - 15; break; } imagecopy($destCanvas, $watermarkImage, $destinationX, $destinationY, 0, 0, $wmWidth, $wmHeight); }
/** * Constructor * * Parses arguments, looks for a command, and hands off command * options to another Relic library function. */ public function __construct() { $this->_parseArgs(); if (array_key_exists($this->command, $this->commands)) { $args = $this->_parseOpts($this->commands[$this->command]['options'], $this->commands[$this->command]['params']); switch ($this->command) { case 'thumb': Image::thumbnail($args['params']['image'], $args['params']['dst'], $args['options']); break; case 'split': PDF::split($args); break; case 'metadata': $mime = Mime::mime($args['params']['file']); if (in_array($mime, array('image/jpg', 'image/jpeg', 'image/tiff'))) { $image = new Image($args['params']['file']); $this->prettyPrint($image->exif()); } else { if ($mime == 'application/pdf') { $pdf = new PDF($args['params']['file']); $this->prettyPrint($pdf->info); } } break; case 'mime': Mime::printMime($args['params']['file']); break; } } else { $this->_usage(false, 'Unknown command.'); exit(1); } }
protected function afterSave() { parent::afterSave(); require_once 'Image.php'; // 保存图片 if ($this->serverFile instanceof CUploadedFile && $this->hasErrors('serverFile') == false) { // 保存原文件 $file = $this->serverFile; $fileName = md5($file->tempName . uniqid()) . '.' . $file->extensionName; $filePath = Helper::mediaPath(self::UPLOAD_ORIGINAL_FILE_PATH . $fileName, FRONTEND); $file->saveAs($filePath); // 如果是图片需要进行裁切 if (strtolower($file->extensionName) != 'swf') { $image = new Image($filePath); $image->resize(350, 230)->save(Helper::mediaPath(self::UPLOAD_THUMBNAIL_IMAGE_PATH . $fileName, FRONTEND)); } // 更新数据 $this->updateByPk($this->primaryKey, array('image_path' => $fileName)); } else { if ($this->deleteServerFile) { // 删除图片 @unlink(Helper::mediaPath(self::UPLOAD_ORIGINAL_FILE_PATH . $this->image_path, FRONTEND)); // 更新数据 $this->updateByPk($this->primaryKey, array('image_path' => '')); } } }
public function actionGetimg() { if (isset($_POST['data'])) { $data = $_POST['data']; $model = new Image(); $criteria = new CDbCriteria(); if ($data[0]) { $criteria->addCondition("is_show=1 and pid={$data['0']} and id<{$data['1']}"); } else { $criteria->addCondition("is_show=1 and id<{$data['1']}"); } $criteria->order = 'id desc'; $criteria->limit = 6; $imgs = $model->findAll($criteria); if (!$imgs) { echo 0; exit; } $html = array(); if ($imgs) { foreach ($imgs as $one) { $html[] = "<div class='item'><div class='animate-box bounceIn animated'>\r\n\t\t\t\t\t<a href='javascript:;' class='image-popup fh5co-board-img' title='{$one->title}'><img src='http://7xssk6.com2.z0.glb.clouddn.com/{$one->img}' alt='s-nice'></a>\t\t\t\t\t\t\r\n\t\t\t\t\t</div>\r\n\t\t\t\t\t<div class='fh5co-desc'>{$one->des}</div></div>"; } $html[] = "<p style='display:none' id='imgid'>{$one->id}</p>"; } $html = json_encode($html); if ($html) { echo $html; exit; } else { echo 0; exit; } } }
/** * Image caching * * Resize & cache image into the file system. Returns the template image if product image is not exists * At this time supports JPG images only * * @param mixed $name * @param int $user_id * @param int $width Resizing width * @param int $height Resizing height * @param bool $watermarked * @param bool $overwrite * @return string Cached Image URL */ public function image($name, $user_id, $width, $height, $watermarked = false, $overwrite = false) { $storage = DIR_STORAGE . $user_id . DIR_SEPARATOR . $name . '.' . ALLOWED_IMAGE_EXTENSION; $cache = DIR_IMAGE . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . $width . '-' . $height . '.' . ALLOWED_IMAGE_EXTENSION; $watermark = DIR_IMAGE . 'common' . DIR_SEPARATOR . 'watermark.png'; $cached_url = ($this->_request->getHttps() ? HTTPS_IMAGE_SERVER : HTTP_IMAGE_SERVER) . 'cache' . DIR_SEPARATOR . $user_id . DIR_SEPARATOR . $name . '-' . $width . '-' . $height . '.' . ALLOWED_IMAGE_EXTENSION; // Force reset if ($overwrite) { unlink($cache); } // If image is cached if (file_exists($cache)) { return $cached_url; // If image not cached } else { // Create directories by path if not exists $directories = explode(DIR_SEPARATOR, $cache); $path = ''; foreach ($directories as $directory) { $path .= DIR_SEPARATOR . $directory; if (!is_dir($path) && false === strpos($directory, '.')) { mkdir($path, 0755); } } // Prepare new image $image = new Image($storage); $image->resize($width, $height); if ($watermarked) { $image->watermark($watermark); } $image->save($cache); } return $cached_url; }
public function resize($filename, $width, $height) { if (!is_file(DIR_IMAGE . $filename)) { return; } $extension = pathinfo($filename, PATHINFO_EXTENSION); $old_image = $filename; $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . '.' . $extension; if (!is_file(DIR_IMAGE . $new_image) || filectime(DIR_IMAGE . $old_image) > filectime(DIR_IMAGE . $new_image)) { $path = ''; $directories = explode('/', dirname(str_replace('../', '', $new_image))); foreach ($directories as $directory) { $path = $path . '/' . $directory; if (!is_dir(DIR_IMAGE . $path)) { @mkdir(DIR_IMAGE . $path, 0777); } } list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image); if ($width_orig != $width || $height_orig != $height) { $image = new Image(DIR_IMAGE . $old_image); $image->resize($width, $height); $image->save(DIR_IMAGE . $new_image); } else { copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image); } } if ($this->request->server['HTTPS']) { return $this->config->get('config_ssl') . 'image/' . $new_image; } else { return $this->config->get('config_url') . 'image/' . $new_image; } }
private function makeImage($image_url, $image_date) { $make_image_size = array(); $make_image_size[] = array("width" => 100, "hight" => 100); $image_file_urls = array(); // 拡張子を取得 $path_parts = pathinfo($image_url); $image_extension = $path_parts['extension']; $image_path = _IMAGE_PATH . $this->RSS_AccountInfo->name; if (!file_exists($image_path)) { mkdir($image_path, 0777); } $imageObj = new Image(); if (!$imageObj->setImage($image_url)) { //画像取得失敗 return array(); } foreach ($make_image_size as $image_size) { $image_file_name = $this->RSS_AccountInfo->name . "_" . date("ymd_His", strtotime($image_date)) . "_" . $image_size['width'] . "x" . $image_size['hight'] . "." . $image_extension; $output_image_path = $image_path . "/" . $image_file_name; $ret = $imageObj->resizeImage($image_size['width'], $image_size['hight'])->output_ImageResource($output_image_path); if ($ret) { $image_file_urls[] = _IMAGE_URL . $this->RSS_AccountInfo->name . "/" . $image_file_name; } } return $image_file_urls; }
public function get_lock_editor_html(Image $image) { global $user; $b_locked = $image->is_locked() ? "Yes (Only admins may edit these details)" : "No"; $h_locked = $image->is_locked() ? " checked" : ""; return "\n\t\t\t<tr>\n\t\t\t\t<th>Locked</th>\n\t\t\t\t<td>\n\t\t" . ($user->can("edit_image_lock") ? "\n\t\t\t\t\t<span class='view'>{$b_locked}</span>\n\t\t\t\t\t<input class='edit' type='checkbox' name='tag_edit__locked'{$h_locked}>\n\t\t" : "\n\t\t\t\t\t{$b_locked}\n\t\t") . "\n\t\t\t\t</td>\n\t\t\t</tr>\n\t\t"; }
public function display_image(Page $page, Image $image) { $data_href = get_base_href(); $ilink = $image->get_image_link(); $html = "\n\t\t\t<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'\n\t\t\t codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0'\n\t\t\t\t\twidth='400' height='15'>\n\t\t\t\t<param name='movie' value='{$data_href}/ext/handle_mp3/xspf_player_slim.swf?song_url={$ilink}'/>\n\t\t\t\t<param name='quality' value='high' />\n\t\t\t\t<embed src='{$data_href}/ext/handle_mp3/xspf_player_slim.swf?song_url={$ilink}' quality='high'\n\t\t\t\t\tpluginspage='http://www.macromedia.com/go/getflashplayer'\n\t\t\t\t\twidth='400' height='15'\n\t\t\t\t\ttype='application/x-shockwave-flash'></embed>\n\t\t\t</object>\n\t\t\t<p><a href='{$ilink}'>Download</a>"; $page->add_block(new Block("Music", $html, "main", 0)); }
public function index() { echo ROOT_PATH . '/code.jpeg'; $img = new Image('/code.jpeg'); $img->thumb(100, 200); $img->out(); }
public function upload() { $file = Input::file('file'); $input = array('image' => $file); $rules = array('image' => 'image'); $validator = Validator::make($input, $rules); $imagePath = 'public/uploads/'; $thumbPath = 'public/uploads/thumbs/'; $origFilename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension(); $mimetype = $file->getMimeType(); if (!in_array($extension, $this->whitelist)) { return Response::json('Supported extensions: jpg, jpeg, gif, png', 400); } if (!in_array($mimetype, $this->mimeWhitelist) || $validator->fails()) { return Response::json('Error: this is not an image', 400); } $filename = str_random(12) . '.' . $extension; $image = ImageKit::make($file); //save the original sized image for displaying when clicked on $image->save($imagePath . $filename); // make the thumbnail for displaying on the page $image->fit(640, 480)->save($thumbPath . 'thumb-' . $filename); if ($image) { $dbimage = new Image(); $dbimage->thumbnail = 'uploads/thumbs/thumb-' . $filename; $dbimage->image = 'uploads/' . $filename; $dbimage->original_filename = $origFilename; $dbimage->save(); return $dbimage; } else { return Response::json('error', 400); } }
public function getHotSpots() { $crawler = new Crawler($this); $outlines = new CrawlerOutlineCollection(); $size = $this->image->size(); for ($x = 0; $x < $size[0]; $x++) { for ($y = 0; $y < $size[1]; $y++) { $pixel = $this->pixel($x, $y); // Skip white pixels if ($pixel->color()->compare(ImageColor::white(), 5)) { continue; } // Skip crawled areas if ($outlines->contains($pixel)) { continue; } // Start crawling $outline = $crawler->crawl($x, $y); $outlines->push($outline); } } $hotspots = new ImageCollection(); foreach ($outlines as $outline) { $hotspots->push($this->image->sliceByOutline($outline)); } return array($hotspots, $outlines); }
/** * Uploadify上传文件处理 */ public function hd_uploadify() { $uploadModel = M('upload'); $size = Q('size') ? Q('size') : C('allow_size'); $upload = new Upload(Q('post.upload_dir'), array(), $size); $file = $upload->upload(); if (!empty($file)) { $file = $file[0]; $file['uid'] = session('uid'); //图片加水印 if ($file['image'] && Q('water')) { $img = new Image(); $img->water($file['path']); } //写入upload表 $uploadModel->add($file); $data = $file; $data['status'] = 1; $data['isimage'] = $file['image'] ? 1 : 0; } else { $data['status'] = 0; $data['message'] = $upload->error; } echo json_encode($data); exit; }