本文整理汇总了PHP中graphics类的典型用法代码示例。如果您正苦于以下问题:PHP graphics类的具体用法?PHP graphics怎么用?PHP graphics使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了graphics类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save()
{
access::verify_csrf();
$form = theme::get_edit_form_admin();
if ($form->validate()) {
module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);
$thumb_size = $form->edit_theme->thumb_size->value;
$thumb_dirty = false;
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "thumb_size", $thumb_size);
}
$resize_size = $form->edit_theme->resize_size->value;
$resize_dirty = false;
if (module::get_var("gallery", "resize_size") != $resize_size) {
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "resize_size", $resize_size);
}
module::set_var("gallery", "header_text", $form->edit_theme->header_text->value);
module::set_var("gallery", "footer_text", $form->edit_theme->footer_text->value);
module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value);
message::success(t("Updated theme details"));
url::redirect("admin/theme_options");
} else {
$view = new Admin_View("admin.html");
$view->content = $form;
print $view;
}
}
示例2: uninstall
static function uninstall()
{
graphics::remove_rules("watermark");
module::delete("watermark");
Database::instance()->query("DROP TABLE `watermarks`");
dir::unlink(VARPATH . "modules/watermark");
}
示例3: save
public function save()
{
access::verify_csrf();
$form = $this->_get_edit_form_admin();
if ($form->validate()) {
module::set_var("gallery", "page_size", $form->edit_theme->page_size->value);
$thumb_size = $form->edit_theme->thumb_size->value;
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => $thumb_size, "height" => $thumb_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "thumb_size", $thumb_size);
}
$resize_size = $form->edit_theme->resize_size->value;
if (module::get_var("gallery", "resize_size") != $resize_size) {
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100);
module::set_var("gallery", "resize_size", $resize_size);
}
module::set_var("gallery", "show_credits", $form->edit_theme->show_credits->value);
// Sanitize values that get placed directly in HTML output by theme.
module::set_var("gallery", "header_text", html::purify($form->edit_theme->header_text->value));
module::set_var("gallery", "footer_text", html::purify($form->edit_theme->footer_text->value));
module::set_var("gallery", "favicon_url", html::purify($form->edit_theme->favicon_url->value));
module::set_var("gallery", "apple_touch_icon_url", html::purify($form->edit_theme->apple_touch_icon_url->value));
module::event("theme_edit_form_completed", $form);
message::success(t("Updated theme details"));
url::redirect("admin/theme_options");
} else {
$view = new Admin_View("admin.html");
$view->content = new View("admin_theme_options.html");
$view->content->form = $form;
print $view;
}
}
示例4: rebuild_dirty_images
/**
* Task that rebuilds all dirty images.
* @param Task_Model the task
*/
static function rebuild_dirty_images($task)
{
$errors = array();
try {
$result = graphics::find_dirty_images_query()->select("id")->execute();
$total_count = $task->get("total_count", $result->count());
$mode = $task->get("mode", "init");
if ($mode == "init") {
$task->set("total_count", $total_count);
$task->set("mode", "process");
batch::start();
}
$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());
$i = 0;
foreach ($result as $row) {
if (array_key_exists($row->id, $ignored)) {
continue;
}
$item = ORM::factory("item", $row->id);
if ($item->loaded()) {
try {
graphics::generate($item);
$completed++;
$errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title)));
} catch (Exception $e) {
$errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title)));
$errors[] = (string) $e;
$ignored[$item->id] = 1;
}
}
if (++$i == 2) {
break;
}
}
$task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $total_count));
if ($completed < $total_count) {
$task->percent_complete = (int) (100 * ($completed + count($ignored)) / $total_count);
} else {
$task->percent_complete = 100;
}
$task->set("completed", $completed);
$task->set("ignored", $ignored);
if ($task->percent_complete == 100) {
$task->done = true;
$task->state = "success";
batch::stop();
site_status::clear("graphics_dirty");
}
} catch (Exception $e) {
Kohana_Log::add("error", (string) $e);
$task->done = true;
$task->state = "error";
$task->status = $e->getMessage();
$errors[] = (string) $e;
}
if ($errors) {
$task->log($errors);
}
}
示例5: 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);
}
示例6: rebuild_dirty_images
/**
* Task that rebuilds all dirty images.
* @param Task_Model the task
*/
static function rebuild_dirty_images($task)
{
$result = graphics::find_dirty_images_query();
$remaining = $result->count();
$completed = $task->get("completed", 0);
$i = 0;
foreach ($result as $row) {
$item = ORM::factory("item", $row->id);
if ($item->loaded) {
graphics::generate($item);
}
$completed++;
$remaining--;
if (++$i == 2) {
break;
}
}
$task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $remaining + $completed));
if ($completed + $remaining > 0) {
$task->percent_complete = (int) (100 * $completed / ($completed + $remaining));
} else {
$task->percent_complete = 100;
}
$task->set("completed", $completed);
if ($remaining == 0) {
$task->done = true;
$task->state = "success";
site_status::clear("graphics_dirty");
}
}
示例7: 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);
}
示例8: item_created
static function item_created($item)
{
// Only works on photos
if (!$item->is_photo()) {
return;
}
// Locate jhead
if (!is_file($path = exec('which jhead'))) {
// @todo throw an exception ?
Kohana::log('error', 'jhead is not installed');
}
$binary = str_replace('\\', '/', realpath(dirname($path)));
$binary .= '/jhead';
$binary .= PHP_SHLIB_SUFFIX === 'dll' ? '.exe' : '';
if (!is_file($binary)) {
// @todo throw an exception ?
Kohana::log('error', 'Unable to locate jhead binary');
}
// Invoke jhead
if ($error = exec(escapeshellcmd($binary) . ' -q -autorot ' . $item->file_path())) {
// @todo throw an exception ?
Kohana::log('error', 'Error during execution of jhead');
}
// Update item
$image_info = getimagesize($item->file_path());
$item->width = $image_info[0];
$item->height = $image_info[1];
$item->resize_dirty = 1;
$item->thumb_dirty = 1;
$item->save();
graphics::generate($item);
}
示例9: install
static function install()
{
// Insert a rule into the thumbnail generation pipeline that converts the source image to the
// right aspect ratio such that when we resize it down, it comes out to the right dimensions.
graphics::add_rule("rectangle_thumbs", "thumb", "rectangle_thumbs_graphics::crop_to_aspect_ratio", array(), 50);
module::set_var("rectangle_thumbs", "aspect_ratio", "3:1");
module::set_version("rectangle_thumbs", 1);
}
示例10: composite
/**
* Overlay an image on top of the input file.
*
* Valid options are: file, mime_type, position, transparency_percent, padding
*
* Valid positions: northwest, north, northeast,
* west, center, east,
* southwest, south, southeast
*
* padding is in pixels
*
* @param string $input_file
* @param string $output_file
* @param array $options
*/
static function composite($input_file, $output_file, $options)
{
try {
graphics::init_toolkit();
module::event("graphics_composite", $input_file, $output_file, $options);
list($width, $height) = getimagesize($input_file);
list($w_width, $w_height) = getimagesize($options["file"]);
$pad = isset($options["padding"]) ? $options["padding"] : 10;
$top = $pad;
$left = $pad;
$y_center = max($height / 2 - $w_height / 2, $pad);
$x_center = max($width / 2 - $w_width / 2, $pad);
$bottom = max($height - $w_height - $pad, $pad);
$right = max($width - $w_width - $pad, $pad);
switch ($options["position"]) {
case "northwest":
$x = $left;
$y = $top;
break;
case "north":
$x = $x_center;
$y = $top;
break;
case "northeast":
$x = $right;
$y = $top;
break;
case "west":
$x = $left;
$y = $y_center;
break;
case "center":
$x = $x_center;
$y = $y_center;
break;
case "east":
$x = $right;
$y = $y_center;
break;
case "southwest":
$x = $left;
$y = $bottom;
break;
case "south":
$x = $x_center;
$y = $bottom;
break;
case "southeast":
$x = $right;
$y = $bottom;
break;
}
Image::factory($input_file)->composite($options["file"], $x, $y, $options["transparency"])->quality(module::get_var("gallery", "image_quality"))->save($output_file);
module::event("graphics_composite_completed", $input_file, $output_file, $options);
} catch (ErrorException $e) {
Kohana::log("error", $e->get_message());
}
}
示例11: user_login
static function user_login($user)
{
// If this user is an admin, check to see if there are any post-install tasks that we need
// to run and take care of those now.
if ($user->admin && module::get_var("gallery", "choose_default_tookit", null)) {
graphics::choose_default_toolkit();
module::clear_var("gallery", "choose_default_tookit");
}
}
示例12: 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);
}
示例13: save
public function save()
{
access::verify_csrf();
$form = self::get_edit_form_admin();
if ($form->validate()) {
$edit_theme = $form->edit_theme;
module::set_var("gallery", "page_size", $edit_theme->row_count->value * 3);
$resize_size = $edit_theme->resize_size->value;
$thumb_size = 200;
$build_resize = $edit_theme->build_resize->value;
$build_thumbs = $edit_theme->build_thumbs->value;
if (module::get_var("gallery", "resize_size") != $resize_size) {
module::set_var("gallery", "resize_size", $resize_size);
$build_resize = true;
}
if (module::get_var("gallery", "thumb_size") != $thumb_size) {
module::set_var("gallery", "thumb_size", $thumb_size);
}
if ($build_resize) {
graphics::remove_rule("gallery", "resize", "gallery_graphics::resize");
graphics::add_rule("gallery", "resize", "gallery_graphics::resize", array("width" => $resize_size, "height" => $resize_size, "master" => Image::AUTO), 100);
}
if ($build_thumbs) {
graphics::remove_rule("gallery", "thumb", "gallery_graphics::resize");
graphics::add_rule("gallery", "thumb", "gallery_graphics::resize", array("width" => 200, "height" => 200, "master" => Image::AUTO), 100);
}
module::set_var("th_greydragon", "photonav_top", $edit_theme->photonav_top->value);
module::set_var("th_greydragon", "photonav_bottom", $edit_theme->photonav_bottom->value);
$sidebar_allowed = $edit_theme->sidebar_allowed->value;
$sidebar_visible = $edit_theme->sidebar_visible->value;
if ($sidebar_allowed == "none") {
$sidebar_visible = "none";
}
if ($sidebar_allowed == "right") {
$sidebar_visible = "right";
}
if ($sidebar_allowed == "left") {
$sidebar_visible = "left";
}
module::set_var("th_greydragon", "sidebar_allowed", $sidebar_allowed);
module::set_var("th_greydragon", "sidebar_visible", $sidebar_visible);
module::set_var("gallery", "header_text", $edit_theme->header_text->value);
module::set_var("gallery", "footer_text", $edit_theme->footer_text->value);
module::set_var("gallery", "show_credits", $edit_theme->show_credits->value);
module::set_var("th_greydragon", "copyright", $edit_theme->copyright->value);
module::set_var("th_greydragon", "logo_path", $edit_theme->logo_path->value);
module::event("theme_edit_form_completed", $form);
message::success(t("Updated theme details"));
url::redirect("admin/theme_options");
} else {
$view = new Admin_View("admin.html");
$view->content = $form;
print $view;
}
}
示例14: remove_album_cover
static function remove_album_cover($album)
{
access::required("edit", $album);
@unlink($album->thumb_path());
model_cache::clear("item", $album->album_cover_item_id);
$album->album_cover_item_id = null;
$album->thumb_width = 0;
$album->thumb_height = 0;
$album->thumb_dirty = 1;
$album->save();
graphics::generate($album);
}
示例15: rebuild_dirty_images
/**
* Task that rebuilds all dirty images.
* @param Task_Model the task
*/
static function rebuild_dirty_images($task)
{
$errors = array();
try {
$result = graphics::find_dirty_images_query();
$completed = $task->get("completed", 0);
$ignored = $task->get("ignored", array());
$remaining = $result->count() - count($ignored);
$i = 0;
foreach ($result as $row) {
if (array_key_exists($row->id, $ignored)) {
continue;
}
$item = ORM::factory("item", $row->id);
if ($item->loaded) {
try {
graphics::generate($item);
$ignored[$item->id] = 1;
$errors[] = t("Successfully rebuilt images for '%title'", array("title" => html::purify($item->title)));
} catch (Exception $e) {
$errors[] = t("Unable to rebuild images for '%title'", array("title" => html::purify($item->title)));
$errors[] = $e->__toString();
}
}
$completed++;
$remaining--;
if (++$i == 2) {
break;
}
}
$task->status = t2("Updated: 1 image. Total: %total_count.", "Updated: %count images. Total: %total_count.", $completed, array("total_count" => $remaining + $completed));
if ($completed + $remaining > 0) {
$task->percent_complete = (int) (100 * $completed / ($completed + $remaining));
} else {
$task->percent_complete = 100;
}
$task->set("completed", $completed);
$task->set("ignored", $ignored);
if ($remaining == 0) {
$task->done = true;
$task->state = "success";
site_status::clear("graphics_dirty");
}
} catch (Exception $e) {
$task->done = true;
$task->state = "error";
$task->status = $e->getMessage();
$errors[] = $e->__toString();
}
if ($errors) {
$task->log($errors);
}
}