本文整理匯總了PHP中Images類的典型用法代碼示例。如果您正苦於以下問題:PHP Images類的具體用法?PHP Images怎麽用?PHP Images使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Images類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: doSaveMedia
public function doSaveMedia($v)
{
if ($v == null) {
$image = $this->getImagePath();
if ($this->isNew) {
$content = file_get_contents(sfConfig::get('sf_root_dir') . '/public_html' . $image);
$size = getimagesize(sfConfig::get('sf_root_dir') . '/public_html' . $image);
} else {
return $this->getObject()->getImagesId();
}
} else {
$content = file_get_contents($v->getTempName());
$size = getimagesize($v->getTempName());
}
$hash = md5($content);
$criteria = new Criteria();
$criteria->add(ImagesPeer::CONTENT_HASH, $hash);
$obj = ImagesPeer::doSelectOne($criteria);
try {
if (empty($obj)) {
$obj = new Images();
$obj->setNameDownloadedFile($v->getOriginalName())->setNameFileForPage($v->getOriginalName())->setTypeImg($v->getType())->setHeight($size[2])->setWidth($size[1])->setContentHash($hash . '.jpg')->setContent(base64_encode($content))->setCreatedAt(date("Y-m-d H:i"))->setUpdatedAt(date("Y-m-d H:i"))->save();
}
} catch (Exception $e) {
echo "stdfdfdfdfrt";
die;
}
$criteria = new Criteria();
$criteria->add(ImagesPeer::CONTENT_HASH, $obj->getContentHash());
$obj = ImagesPeer::doSelectOne($criteria);
return $obj->getId();
}
示例2: actionView
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
$imagesModel = new Images();
$images = $imagesModel->getData($id);
$userId = Albums::getAlbumAuthor($id);
$this->render('view', array('model' => $this->loadModel($id), 'dataProvider' => $images, 'id' => $userId));
}
示例3: saveEdit
public function saveEdit(Images $img)
{
try {
$db = $this->connectionToDataBase();
$sql = "UPDATE {$this->tabel} SET " . self::$Comment . " = ? WHERE imgName = ?";
$params = array($img->GetMSG(), $img->getImgName());
$query = $db->prepare($sql);
$query->execute($params);
} catch (Exception $e) {
die('An unknown error hase happened');
}
}
示例4: save
public function save()
{
$transaction = Yii::$app->db->beginTransaction();
try {
$characteristics = new Characteristics();
$characteristics->display_type = $this->displayType;
$characteristics->mechanism_type = $this->mechanismType;
$characteristics->starp_type = $this->starpType;
$characteristics->sex = $this->sex;
if (!$characteristics->save(false)) {
throw new \Exception('Charasteristic not save, transaction rollback');
}
$products = new Products();
$products->clk_name = $this->name;
$products->clk_description = $this->description;
$products->characteristics_id = $characteristics->id;
$products->price = $this->price;
if (!$products->save(false)) {
throw new \Exception('Product not save, transaction rollback');
}
$hashName = Yii::$app->security->generateRandomString();
$fullImagePath = self::FULL_IMAGES_PATH . $hashName . '.' . $this->images->extension;
if (!$this->images->saveAs($fullImagePath)) {
throw new \Exception('Image not save in full image path');
}
$imgSizeReduct = function ($side = 'width') use($fullImagePath) {
$size = getimagesize($fullImagePath);
if ($side === 'width') {
return $size[0] / self::THUMB_REDUCTION;
}
if ($side === 'height') {
return $size[1] / self::THUMB_REDUCTION;
}
};
$images = new Images();
$transformation = new Transformation();
$imagine = new Imagine();
$transformation->thumbnail(new Box($imgSizeReduct('width'), $imgSizeReduct('height')))->save(Yii::getAlias('@webroot/' . self::THUMBS_IMAGES_PATH . $hashName . '.' . $this->images->extension));
$transformation->apply($imagine->open(Yii::getAlias('@webroot/' . self::FULL_IMAGES_PATH . $hashName . '.' . $this->images->extension)));
$images->product_id = $products->id;
$images->img_name = $hashName . '.' . $this->images->extension;
if (!$images->save(false)) {
throw new \Exception('Images not save, transaction rollback');
}
$transaction->commit();
Yii::$app->session->addFlash('success', 'Product successfully added');
} catch (\Exception $e) {
$transaction->rollBack();
throw $e;
}
}
示例5: prepareText
protected function prepareText($post)
{
/*Если не указан main_pic то найдем првй попавшейся по посту и поставим*/
if (empty($post['main_pic']) && !empty($post['id'])) {
$img_arr = Images::items($post['id']);
/*Если что то найдет то вставит*/
if (!empty($img_arr)) {
reset($img_arr);
$img_arr = current($img_arr);
$post['main_pic'] = $img_arr['file_name'];
}
} elseif (!empty($post['main_pic'])) {
$post['main_pic'] = explode("/", $post['main_pic']);
$post['main_pic'] = end($post['main_pic']);
$post['main_pic'] = trim($post['main_pic']);
}
/**подготавливаем текст для сохранения*/
$post['full_text'] = $post['content'];
if ($str_res = strpos($post['full_text'], '<!--more-->')) {
$post['text_preview'] = substr($post['full_text'], 0, $str_res);
} else {
$post['full_text'] = strip_tags($post['full_text']);
$post['text_preview'] = substr($post['full_text'], 0, 400);
if ($str_res = strripos($post['text_preview'], ' ')) {
$post['text_preview'] = substr($post['text_preview'], 0, $str_res);
}
}
$post['full_text'] = str_replace('<!--more-->', " ", $post['content']);
return $post;
}
示例6: GetImagePath
static function GetImagePath($id, $type, $suffix)
{
$fileName = md5(time() . $id . "_" . $suffix);
$storePath = Images::IMAGE_STORE_ROOT_PATH . $type . "/" . Images::Kmod($id) . "/";
$webPath = Images::IMAGE_WEB_ROOT_PATH . $type . "/" . Images::Kmod($id) . "/" . $fileName;
return array($storePath, $fileName, $webPath);
}
示例7: run
public function run($class_name)
{
$path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
$class_name = ucfirst($class_name);
if ($path && is_dir($path) && is_writable($path)) {
$dir = key($_GET);
$filename = $_GET[$dir];
$pk = pathinfo($filename, PATHINFO_FILENAME);
$image = Images::model()->findByPk($pk);
if ($image != null) {
$image->resize($dir);
}
} elseif (class_exists($class_name)) {
$dir = key($_GET);
$filename = $_GET[$dir];
$size = explode('x', $dir);
$path = realpath(Yii::app()->basePath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'upload' . DIRECTORY_SEPARATOR . $class_name);
if (YII_DEBUG && !file_exists($path . DIRECTORY_SEPARATOR . $dir)) {
mkdir($path . DIRECTORY_SEPARATOR . $dir, 0777);
}
if ($path !== FALSE && file_exists($path . DIRECTORY_SEPARATOR . $dir) && is_file($path . DIRECTORY_SEPARATOR . $filename) && $size[0] > 0 && $size[1] > 0) {
Yii::import('ext.iwi.Iwi');
$image = new Iwi($path . DIRECTORY_SEPARATOR . $filename);
$image->adaptive($size[0], $size[1]);
$image->save($path . DIRECTORY_SEPARATOR . $dir . DIRECTORY_SEPARATOR . $filename, 0644, TRUE);
$mime = CFileHelper::getMimeType($path . DIRECTORY_SEPARATOR . $filename);
header('Content-Type: ' . $mime);
$image->render();
exit;
}
}
return parent::run($class_name);
}
示例8: getImageInfo
/**
* Load image info based on the id
*/
public function getImageInfo($id)
{
$image = Images::findFirst($id);
if (!$image) {
die('image not found!');
}
$sql = 'select x, y, value, name as text FROM images_tags left join tags on images_tags.tag_id = tags.id WHERE confidence is null AND images_tags.image_id = ' . $id;
$resultSet = $this->getDI()->get('db')->query($sql);
$resultSet->setFetchMode(Phalcon\Db::FETCH_ASSOC);
//Get tags
$tags = $image->getTags()->toArray();
//Get imageTags
$imageTags = $image->getImagesTags()->toArray();
$result = [];
$result['image'] = $image;
//Add tags
$result['tags'] = $resultSet->fetchAll();
//Load additional information
$additionalDataSql = 'select * from additional_image_info a WHERE a.filename = \'' . $image->filename . '\' LIMIT 1';
$resultSet2 = $this->getDI()->get('db')->query($additionalDataSql);
$resultSet2->setFetchMode(Phalcon\Db::FETCH_ASSOC);
$addData = $resultSet2->fetchAll();
//The data added depends on the type of information present
if (isset($addData[0])) {
$result['additional_info'] = $addData[0];
} else {
$result['additional_info'] = [];
$result['additional_info']['fotograf'] = null;
}
//Adds a default photographer if no name is given
if ($result['additional_info']['fotograf'] == null || $result['additional_info']['fotograf'] == '' || $result['additional_info']['fotograf'] == '?') {
$result['additional_info']['fotograf'] = 'DR';
}
return $result;
}
示例9: savePost
public function savePost()
{
$post = ['title' => Input::get('title'), 'content' => Input::get('content'), 'picture' => Input::get('picture')];
$rules = ['title' => 'required', 'content' => 'required'];
$valid = Validator::make($post, $rules);
if ($valid->passes()) {
$post = new Post($post);
$post->comment_count = 0;
$post->read_more = strlen($post->content) > 120 ? substr($post->content, 0, 120) : $post->content;
/*
$destinationPath = 'uploads'; // upload path
//$extension = Input::file('image')->getClientOriginalExtension(); // getting image extension
$fileName = time(); // renameing image
Input::file('images')->make($destinationPath, $fileName); // uploading file to given path
$post->images = Input::get($fileName);
$pic = Input::file('picture');
$pic_name = time();
Image::make($pic)->save(public_path().'/images/300x'.$pic_name);
$post->images = '/images/'.'300x'.$pic_name;
$post->images = Input::get($pic_name);
*/
$file = Request::file('picture');
$extension = $file;
Images::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
$post->images = $file->time();
$post->save();
return Redirect::to('admin/dash-board')->with('success', 'Post is saved!');
} else {
return Redirect::back()->withErrors($valid)->withInput();
}
}
示例10: add
function add($request, $response, $args)
{
$body = $request->getParsedBody();
if (!isset($_FILES['image'])) {
echo "No files uploaded!!";
return;
}
$name = $_FILES['image']['name'];
if (move_uploaded_file($_FILES['image']['tmp_name'], 'uploads/' . $name) === true) {
$url = 'uploads/' . $name;
}
$image = new Images();
$image->title = $body['title'];
$image->url = $url;
$image->save();
}
示例11: actionConvert
public function actionConvert()
{
@set_time_limit(0);
@ini_set('max_execution_time', 0);
$sql = 'SELECT id, owner_id FROM {{apartment}} WHERE 1';
$res = Yii::app()->db->createCommand($sql)->queryAll();
$ids = CHtml::listData($res, 'id', 'owner_id');
$sql = 'SELECT pid, imgsOrder FROM {{galleries}} WHERE 1';
$res = Yii::app()->db->createCommand($sql)->queryAll();
if ($res) {
foreach ($res as $item) {
$images = unserialize($item['imgsOrder']);
if (!isset($ids[$item['pid']])) {
continue;
}
if ($images) {
$cnt = 0;
foreach ($images as $image => $name) {
$filePath = Yii::getPathOfAlias('webroot.uploads.apartments.' . $item['pid'] . '.pictures') . '/' . $image;
Images::addImage($filePath, $item['pid'], $cnt == 0, $ids[$item['pid']]);
$cnt++;
}
}
}
}
}
示例12: layout
/**
* list images
*
* @param resource the SQL result
* @return string the rendered text
*
* @see layouts/layout.php
**/
function layout($result)
{
global $context;
// empty list
if (!SQL::count($result)) {
$output = array();
return $output;
}
// we return an array of ($url => $attributes)
$items = array();
// process all items in the list
while ($item = SQL::fetch($result)) {
// url to view the image
$url = Images::get_url($item['id']);
// initialize variables
$prefix = $suffix = '';
// flag new images
if ($item['edit_date'] >= $context['fresh']) {
$suffix .= NEW_FLAG;
}
// image title or image name
$label = Skin::strip($item['title'], 10);
if (!$label) {
$name_as_title = TRUE;
$label = ucfirst($item['image_name']);
}
$label = str_replace('_', ' ', str_replace('%20', ' ', $label));
// list all components for this item
$items[$url] = array($prefix, $label, $suffix, 'basic', NULL);
}
// end of processing
SQL::free($result);
return $items;
}
示例13: store
/**
* Store a newly created user in storage.
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$this->checkPermission('users-manage');
$validationRules = ['name' => 'required', 'email' => 'required|email|unique:users,email'];
$authMethod = config('auth.method');
if ($authMethod === 'standard') {
$validationRules['password'] = 'required|min:5';
$validationRules['password-confirm'] = 'required|same:password';
} elseif ($authMethod === 'ldap') {
$validationRules['external_auth_id'] = 'required';
}
$this->validate($request, $validationRules);
$user = $this->user->fill($request->all());
if ($authMethod === 'standard') {
$user->password = bcrypt($request->get('password'));
} elseif ($authMethod === 'ldap') {
$user->external_auth_id = $request->get('external_auth_id');
}
$user->save();
if ($request->has('roles')) {
$roles = $request->get('roles');
$user->roles()->sync($roles);
}
// Get avatar from gravatar and save
if (!config('services.disable_services')) {
$avatar = \Images::saveUserGravatar($user);
$user->avatar()->associate($avatar);
$user->save();
}
return redirect('/settings/users');
}
示例14: ThumbMaker
function ThumbMaker()
{
global $path;
// Создаем массив с которым будем работать;
// Если существуют оба массива;
if (count($_SESSION['good_dbimages_file']) > 0 and count($_SESSION['good_images_file']) > 0) {
$working_array = array_merge($_SESSION['good_dbimages_file'], $_SESSION['good_images_file']);
goto make_thumb;
}
// Если существует только один массив;
if (count($_SESSION['good_dbimages_file']) > 0) {
$working_array = $_SESSION['good_dbimages_file'];
}
if (count($_SESSION['good_images_file']) > 0) {
$working_array = $_SESSION['good_images_file'];
}
make_thumb:
if (isset($working_array)) {
// Функция для сортировки массива по положению фотографий;
function sortBy($arr, $sortKey)
{
// Временный массив для сотритовки по нужному ключу;
$tempArr = array();
// Возвращаемый массив;
$returnArr = array();
// Перебор всего массива;
foreach ($arr as $key => $value) {
// Запись в массив значений ключа по которому быдет выполнена сортировка;
$tempArr[$key] = $value[$sortKey];
}
// Сортировка значений с сохранением ключей;
asort($tempArr);
// Установка указателя массива не первый элемент;
reset($tempArr);
// Перебор всего временного массива;
foreach ($tempArr as $key => $value) {
// Формирование возвращаемого массива;
$returnArr[] = $arr[$key];
}
return $returnArr;
}
$new_array = sortBy($working_array, 'position');
$thumb_images = new Images();
$thumb_images->Thumber($new_array, $path, 200, 200, 1, 1, 1);
return $thumb_images->result;
}
}
示例15: loadModel
public function loadModel($id)
{
$model = Images::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, 'Страница не найдена');
}
return $model;
}