本文整理汇总了PHP中Image::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::factory方法的具体用法?PHP Image::factory怎么用?PHP Image::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Image
的用法示例。
在下文中一共展示了Image::factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: beforeSave
protected function beforeSave()
{
if (!parent::beforeSave()) {
return false;
}
if (($this->scenario == 'insert' || $this->scenario == 'update') && ($this->icon = CUploadedFile::getInstance($this, 'icon'))) {
// Если обновляем запись, то удаляем прошлую фотографию
if ($this->scenario == 'update') {
$file = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->getBaseUrl() . '/Image/Stock/' . $this->img;
$fileMini = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->getBaseUrl() . '/Image/Stock/mini-' . $this->img;
if (file_exists($file) and $this->img != '') {
unlink($file);
}
if (file_exists($fileMini) and $this->img != '') {
unlink($fileMini);
}
}
$fileName = mktime(date("i")) . '.jpg';
$this->img = $fileName;
$file = $_SERVER['DOCUMENT_ROOT'] . Yii::app()->getBaseUrl() . '/Image/Stock/' . $fileName;
$this->icon->saveAs($file);
//Делаем ресайз только что загруженному изображению
$Image = Image::factory("./Image/Stock/" . $fileName);
if ($Image->width >= $Image->height) {
$Image->resize(375, 410, Image::WIDTH)->crop(375, 410, "top", "center");
$Image->save($_SERVER['DOCUMENT_ROOT'] . Yii::app()->getBaseUrl() . '/Image/Stock/mini-' . $fileName);
} else {
$Image->resize(235, 314, Image::HEIGHT)->crop(235, 314, "top", "center");
$Image->save($_SERVER['DOCUMENT_ROOT'] . Yii::app()->getBaseUrl() . '/Image/Stock/mini-' . $fileName);
}
}
return true;
}
示例2: instance
/**
* Creates a new instance for static use of the class.
*
* @return Image_Driver
*/
protected static function instance()
{
if (Image::$_instance == null) {
Image::$_instance = Image::factory();
}
return Image::$_instance;
}
示例3: crop_to_aspect_ratio
/**
* Crop the input image so that it matches the aspect ratio specified in the
* rectangle_thumbs.aspect_ratio module setting. Focus on the center of the image and crop out
* the biggest piece that we can.
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function crop_to_aspect_ratio($input_file, $output_file, $options)
{
graphics::init_toolkit();
if (@filesize($input_file) == 0) {
throw new Exception("@todo EMPTY_INPUT_FILE");
}
list($desired_width, $desired_height) = explode(":", module::get_var("rectangle_thumbs", "aspect_ratio"));
$desired_ratio = $desired_width / $desired_height;
// Crop the largest rectangular section we can out of the original image. Start with a
// rectangular section that's guaranteed to be too large, then shrink it horizontally to just
// barely fit. If it's still too tall vertically, shrink both dimensions proportionally until
// the horizontal edge fits as well.
$dims = getimagesize($input_file);
if ($desired_ratio == 1) {
$new_width = $new_height = min($dims[0], $dims[1]);
} else {
if ($desired_ratio < 1) {
list($new_width, $new_height) = array($dims[0], $dims[0] / $desired_ratio);
} else {
list($new_width, $new_height) = array($dims[1] * $desired_ratio, $dims[1]);
}
}
if ($new_width > $dims[0]) {
// Too wide, scale it down
list($new_width, $new_height) = array($dims[0], $dims[0] / $desired_ratio);
}
if ($new_height > $dims[1]) {
// Too tall, scale it down some more
$new_width = min($dims[0], $dims[1] * $desired_ratio);
$new_height = $new_width / $desired_ratio;
}
$new_width = round($new_width);
$new_height = round($new_height);
Image::factory($input_file)->crop($new_width, $new_height)->quality(module::get_var("gallery", "image_quality"))->save($output_file);
}
示例4: index
function index()
{
if (!empty($_GET['img']) and !empty($_GET['h']) and !empty($_GET['w'])) {
$img = Image::factory('media/images/' . $_GET['img'])->resize($_GET['w'], $_GET['h'], Image::NONE)->render('jpg', 60);
return $img;
}
}
示例5: rotate
/**
* Rotate an image. Valid options are degrees
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function rotate($input_file, $output_file, $options)
{
graphics::init_toolkit();
module::event("graphics_rotate", $input_file, $output_file, $options);
// BEGIN mod to original function
$image_info = getimagesize($input_file);
// [0]=w, [1]=h, [2]=type (1=GIF, 2=JPG, 3=PNG)
if (module::get_var("image_optimizer", "rotate_jpg") || $image_info[2] == 2) {
// rotate_jpg enabled, the file is a jpg. get args
$path = module::get_var("image_optimizer", "path_jpg");
$exec_args = " -rotate ";
$exec_args .= $options["degrees"] > 0 ? $options["degrees"] : $options["degrees"] + 360;
$exec_args .= " -copy all -optimize -outfile ";
// run it - from input_file to tmp_file
$tmp_file = image_optimizer::make_temp_name($output_file);
exec(escapeshellcmd($path) . $exec_args . escapeshellarg($tmp_file) . " " . escapeshellarg($input_file), $exec_output, $exec_status);
if ($exec_status || !filesize($tmp_file)) {
// either a blank/nonexistant file or an error - log an error and pass to normal function
Kohana_Log::add("error", "image_optimizer rotation failed on " . $output_file);
unlink($tmp_file);
} else {
// worked - move temp to output
rename($tmp_file, $output_file);
$status = true;
}
}
if (!$status) {
// we got here if we weren't supposed to use jpegtran or if jpegtran failed
// END mod to original function
Image::factory($input_file)->quality(module::get_var("gallery", "image_quality"))->rotate($options["degrees"])->save($output_file);
// BEGIN mod to original function
}
// END mod to original function
module::event("graphics_rotate_completed", $input_file, $output_file, $options);
}
示例6: _upload_image
public function _upload_image(Validate $array, $input)
{
if ($array->errors()) {
// Don't bother uploading
return;
}
// Get the image from the array
$image = $array[$input];
if (!Upload::valid($image) or !Upload::not_empty($image)) {
// No need to do anything right now
return;
}
if (Upload::valid($image) and Upload::type($image, $this->types)) {
$filename = strtolower(Text::random('alnum', 20)) . '.jpg';
if ($file = Upload::save($image, NULL, $this->directory)) {
Image::factory($file)->resize($this->width, $this->height, $this->resize)->save($this->directory . $filename);
// Update the image filename
$array[$input] = $filename;
// Delete the temporary file
unlink($file);
} else {
$array->error('image', 'failed');
}
} else {
$array->error('image', 'valid');
}
}
示例7: cache
private function cache()
{
// is it a remote image?
if ($this->is_remote()) {
$path = $this->image_folder . '/imagecache/original';
$image_original_name = "{$path}/" . preg_replace('/\\W/i', '-', $this->image_src);
if (!file_exists($image_original_name)) {
//make sure the directory(s) exist
System::mkdir($path);
// download image
copy($this->image_src, $image_original_name);
}
unset($path);
} else {
// $image_original_name = Route::get('media')->uri(array('file' => $this->image_src));
$image_original_name = Kohana::find_file('media', $this->image_src, FALSE);
}
//if image file not found stop here
if (!$this->is_valid($image_original_name)) {
return FALSE;
}
$this->resized_image = "{$this->image_folder}/imagecache/{$this->resize_type}/{$this->width}x{$this->height}/{$this->image_src}";
if (!file_exists($this->resized_image)) {
//make sure the directory(s) exist
$path = pathinfo($this->resized_image, PATHINFO_DIRNAME);
System::mkdir($path);
// Save the resized image to the public directory for future requests
$image_function = $this->resize_type === 'crop' ? 'crop' : 'resize';
Image::factory($image_original_name)->{$image_function}($this->width, $this->height)->save($this->resized_image, 85);
}
return TRUE;
}
示例8: action_index
public function action_index()
{
//путь до картинки
$src = 'img/user/kottedzh-russkiy-dar_e26ce03e3c12ea32a84.JPG';
$image = Image::factory(getcwd() . DIRECTORY_SEPARATOR . $src);
$image->resize(800, 600);
}
示例9: action_preview2
public function action_preview2()
{
$dir = $this->uploads_dir();
// build image file name
$filename = $this->request->param('filename');
// check if file exists
if (!file_exists($filename) or !is_file($filename)) {
throw new HTTP_Exception_404('Picture not found');
}
$cachenamearr = explode('/', $filename);
$name = array_pop($cachenamearr);
$cachename = 'a2' . $name;
$cachename = str_replace($name, $cachename, $filename);
/** @var Image $image **/
// trying get picture preview from cache
if (($image = Cache::instance()->get($cachename)) === NULL) {
// create new picture preview
$image = Image::factory($filename)->resize(null, 50)->crop(50, 50)->render(NULL, 90);
// store picture in cache
Cache::instance()->set($cachename, $image, Date::MONTH);
}
// gets image type
$info = getimagesize($filename);
$mime = image_type_to_mime_type($info[2]);
// display image
$this->response->headers('Content-type', $mime);
$this->response->body($image);
}
示例10: action_save
public function action_save($pid = null)
{
$data = (object) filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
$photo = ORM::factory("dlsliderphoto", $pid);
$slider = ORM::factory("dlslidergroup", $data->slider_id);
$new = empty($photo->id);
if (!$slider->loaded()) {
Message::set(Message::ERROR, "Something unexpected happened. Please try again.");
$this->request->redirect("admin/dlslider/");
return;
}
$files = Validate::factory($_FILES);
$files->rule('photo', 'Upload::type', array(array('jpg', 'png', 'gif')));
foreach ($data as $val) {
if (empty($val)) {
Message::set(Message::ERROR, "All fields must be filled in.");
$this->request->redirect("admin/dlslider/edit/{$slider->id}");
return;
}
}
$photo->title = $data->title;
$photo->teaser = $data->teaser;
$photo->link_text = $data->linktext;
$photo->link = $data->link;
$photo->saved = isset($data->save) ? 1 : 0;
if (empty($photo->position)) {
$photo->position = $slider->allPhotos->count() + 1;
}
if ($files->check()) {
if ($_FILES['photo']['error'] == 0) {
$filename = upload::save($_FILES['photo'], $_FILES['photo']['name'], Kohana::config('myshot.relativeBase'));
// New file name
$new_filename = rand(0, 1000) . "_" . substr($_FILES['photo']['name'], 0, strlen($_FILES['photo']['name']) - 4) . '-resized' . substr($_FILES['photo']['name'], -4);
$localFile = Kohana::config('myshot.relativeBase') . $new_filename;
// Resize, sharpen, and save the image
Image::factory($filename)->resize(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, Image::WIDTH)->crop(Model_DLSliderPhoto::WIDTH, Model_DLSliderPhoto::HEIGHT, 0, 0)->save($localFile);
Library_Akamai::factory()->addToDir($localFile, "dlslider", date("Y-m"));
$photo->filename = "dlslider/" . date("Y-m") . "/{$new_filename}";
// Remove the temporary files
unlink($filename);
unlink($localFile);
}
}
if (empty($photo->filename)) {
Message::set(Message::ERROR, "Something was wrong with the file to upload. Please check the file try again.");
$this->request->redirect("admin/dlslider/edit/{$slider->id}");
return;
}
$photo->save();
if ($new) {
DB::update("dl_slider_group_dl_slider_photos")->set(array("position" => $slider->allPhotos->count()))->where("dl_slider_group_id", "=", $slider->id)->where("dl_slider_photos_id", "=", $photo->id)->execute();
}
!$slider->has("photos", $photo) ? $slider->add("photos", $photo) : null;
Message::set(Message::SUCCESS, "Image Added");
$this->request->redirect("admin/dlslider/edit/{$slider->id}");
}
示例11: crop_to_square
/**
* Crop the input image so that it's square. Focus on the center of the image.
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function crop_to_square($input_file, $output_file, $options)
{
graphics::init_toolkit();
if (@filesize($input_file) == 0) {
throw new Exception("@todo EMPTY_INPUT_FILE");
}
$size = module::get_var("gallery", "thumb_size");
$dims = getimagesize($input_file);
Image::factory($input_file)->crop(min($dims[0], $dims[1]), min($dims[0], $dims[1]))->quality(module::get_var("gallery", "image_quality"))->save($output_file);
}
示例12: not_nude_image
/**
* Image nudity detector based on flesh color quantity.
*
* @param array $file uploaded file data
* @param string $threshold Threshold of flesh color in image to consider in pornographic. See page 302
* @return boolean
*/
public static function not_nude_image(array $file, $threshold = 0.5)
{
if (Upload::not_empty($file)) {
$image = Image::factory($file['tmp_name']);
if ($image->is_nude_image($threshold)) {
return FALSE;
}
}
return TRUE;
}
示例13: save_uploaded_image
public static function save_uploaded_image($image, $target_path)
{
if (Model_Image::validate_uploaded_image($image)) {
if ($file = Upload::save($image, NULL, DOCROOT . "images/")) {
Image::factory($file)->save($target_path);
// Delete the temporary file
unlink($file);
return TRUE;
}
}
return FALSE;
}
示例14: action_get_image
public function action_get_image()
{
$this->auto_render = FALSE;
if (Arr::get($_SERVER, 'HTTP_X_REQUESTED_WITH', '') == 'XMLHttpRequest') {
$image = ORM::factory('image', Arr::get($_POST, 'id'));
$image = Arr::merge($image->as_array(), Arr::extract((array) Image::factory('images/' . $image->id . '/original' . $image->ext), array('width', 'height')));
$this->response->headers('Content-Type: application/json; charset=utf-8');
$this->response->body(json_encode($image));
} else {
$this->response->body('Only AJAX request');
}
}
示例15: exact
public static function exact($filename, $width, $height)
{
$img = Image::factory($filename)->resize($width, $height, Image::INVERSE)->crop($width, $height);
$nameparts = explode('/', $filename);
$fname = end($nameparts);
$path = implode('/', array_slice($nameparts, 0, count($nameparts) - 1)) . '/';
$filenameparts = explode('.', $fname);
$newname = implode('.', array_slice($filenameparts, 0, count($filenameparts) - 1)) . $width . 'x' . $height . '.' . self::imgtype_to_ext($img->type);
$img->save($path . $newname);
$img->file = $newname;
return $img;
}