本文整理汇总了PHP中Image类的典型用法代码示例。如果您正苦于以下问题:PHP Image类的具体用法?PHP Image怎么用?PHP Image使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Image类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resize
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;
}
}
示例2: build_thumb_html
/**
* 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";
}
示例3: afterSave
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' => ''));
}
}
}
示例4: createImageKey
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;
}
示例5: resize
/**
*
* @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);
}
示例6: generate_thumb
public function generate_thumb()
{
$image = new Image($this->get_image_path());
$image->resize(200, 200);
$image->save($this->get_thumb_path());
return TRUE;
}
示例7: confirm
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);
}
示例8: Thumb
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;
}
示例9: post_instagram
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!');
}
}
}
示例10: display_image
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));
}
示例11: afterSave
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' => ''));
}
}
}
示例12: build_stats
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;
}
示例13: resize
/**
*
* @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;
}
}
示例14: genImgForSlider
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;
}
示例15: resize
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;
}
}