1
0

Merge pull request #98 from mikemayer67/master

[emboss]  New user contributed module
This commit is contained in:
Bharat Mediratta 2012-02-21 20:05:38 -08:00
commit 53eb0c159f
11 changed files with 1111 additions and 4 deletions

View File

@ -0,0 +1,71 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class Admin_Emboss_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View('admin.html');
$view->page_title = t('Emboss');
$view->content = new View('admin_emboss.html');
$images = ORM::factory('emboss_overlay')->find_all();
$view->content->images = $images;
$view->content->emboss_thumbs = module::get_var('emboss','thumbs',0);
$view->content->emboss_resize = module::get_var('emboss','resize',1);
$view->content->emboss_full = module::get_var('emboss','full',1);
print $view;
}
static function update() {
access::verify_csrf();
emboss::update_overlay_options($_POST);
emboss::evaluate_overlays();
emboss::check_for_dirty();
url::redirect('admin/emboss');
}
static function new_overlay() {
access::verify_csrf();
$file = $_FILES['overlay'];
emboss::upload_new_overlay($file);
emboss::check_for_dirty();
url::redirect('admin/emboss');
}
static function delete_overlay() {
access::verify_csrf();
emboss::_delete_overlay($_REQUEST['name']);
emboss::check_for_dirty();
url::redirect('admin/emboss');
}
static function clear_log() {
db::build()
->delete()
->from('logs')
->where('category','=','emboss')
->execute();
url::redirect('admin/emboss');
}
static function uninstall() {
access::verify_csrf();
emboss::uninstall();
url::redirect('admin/modules');
}
}

View File

@ -0,0 +1,459 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class emboss_Core {
static function reconcile()
{
emboss::copy_new(VARPATH . 'albums', VARPATH . 'originals');
emboss::remove_old(VARPATH . 'albums', VARPATH . 'originals');
}
private function error($msg)
{
log::error('emboss',$msg);
message::error($msg);
}
private function success($msg)
{
log::success('emboss',$msg);
message::success($msg);
}
private function info($msg)
{
log::info('emboss',$msg);
message::info($msg);
}
private function copy_new($src,$dst)
{
if( ! is_dir($src) )
return;
if(! file_exists($dst) )
{
log::info('emboss',"Creating directory $dst");
if(! @mkdir($dst) )
{
emboss::error("Failed to create $dst");
return;
}
}
if(! is_dir($dst) )
{
emboss::error("Existing $dst is not a directory");
return;
}
if( ! ($dh = opendir($src)) )
{
emboss::error("Failed to open $src for reading");
return;
}
while( $file = readdir($dh) )
{
if($file=='.'||$file=='..')
continue;
$srcpath = $src . '/' . $file;
$dstpath = $dst . '/' . $file;
if( is_dir($srcpath) )
{
emboss::copy_new($srcpath, $dstpath);
}
else
{
if(! file_exists($dstpath) )
{
log::info('emboss',"Copying $file to $dst");
if(! @copy($srcpath,$dstpath) )
{
emboss::error("Failed to copy $file to $dst");
}
}
}
}
closedir($dh);
}
private function remove_old($src,$archive)
{
if( ! is_dir($archive) )
return;
if(! (file_exists($src) && is_dir($src)) )
{
log::info('emboss',"Removing directory $src");
emboss::rmdir_recursive($archive);
return;
}
if( ! ($dh = opendir($archive)) )
{
emboss::error("Failed to open $archive for reading");
return;
}
while( $file = readdir($dh) )
{
if($file=='.' || $file=='..')
continue;
$srcpath = $src . '/' . $file;
$archivepath = $archive . '/' . $file;
if( is_dir($archivepath) )
{
emboss::remove_old($srcpath,$archivepath);
}
else
{
if( ! file_exists($srcpath) )
{
log::info('emboss',"Removing $file from $archive");
if(! @unlink($archivepath) )
emboss::error("Failed to remove $file from $archive");
}
}
}
closedir($dh);
}
private function rmdir_recursive($dir) {
if(!$dh = @opendir($dir))
return;
while ( $obj = readdir($dh))
{
if($obj=='.' || $obj=='..') continue;
if (!@unlink($dir.'/'.$obj))
emboss::rmdir_recursive($dir.'/'.$obj);
}
closedir($dh);
@rmdir($dir);
}
static function mkdir_recursive($dir) {
$dirs = explode('/', $dir);
$newdir = '';
for($i=1; $i<count($dirs); $i++)
{
$newdir = $newdir . '/' . $dirs[$i];
if(!file_exists($newdir))
{
log::info('emboss',"mkdir $newdir");
@mkdir($newdir);
}
}
}
static function upload_new_overlay($file)
{
$tmp = $file['tmp_name'];
$name = $file['name'];
switch($file['error']) {
case UPLOAD_ERR_INI_SIZE:
emboss::error(t("File size of $name exceeds maximum upload limit on server"));
return;
break;
case UPLOAD_ERR_FORM_SIZE:
emboss::error(t("File size of $name exceeds maximum upload limit set on page"));
return;
break;
case UPLOAD_ERR_PARTIAL:
emboss::error(t("File $name only partially uploaded"));
return;
break;
case UPLOAD_ERR_NO_FILE:
emboss::error(t("File $name failed to upload"));
return;
break;
}
$image_info = getimagesize($tmp);
$types[] = IMAGETYPE_GIF;
$types[] = IMAGETYPE_JPEG;
$types[] = IMAGETYPE_PNG;
if(! $image_info || ! in_array($image_info[2],$types) ) {
emboss::error(t('Overlay image must be GIF, JPG, or PNG'));
@unlink($tmp);
return;
}
$n = db::build()
->select('id')
->from('emboss_overlays')
->where('name','=',$name)
->execute()
->count();
if($n>0) {
emboss::error(t("Overlay named $name already exists."));
@unlink($tmp);
return;
}
$width = $image_info[0];
$height = $image_info[1];
$where1 = array('width','=',$width);
$where2 = array('height','=',$height);
$where = array($where1,$where2);
$n = db::build()
->select('id')
->from('emboss_overlays')
->where('width','=',$width)
->where('height','=',$height)
->execute()
->count();
if($n>0) {
emboss::error(t("Overlay with dimensions $width x $height already exists."));
@unlink($tmp);
return;
}
@rename($tmp, VARPATH . 'modules/emboss/' . $name);
$overlay = ORM::factory('emboss_overlay');
$overlay->name = $name;
$overlay->width = $width;
$overlay->height = $height;
$overlay->active = 1;
$overlay->save();
emboss::success('Succesfully uploaded overlay ' . $file['name']);
emboss::evaluate_overlays();
}
static function _delete_overlay($overlay)
{
$query = db::build()
->select('id')
->from('emboss_overlays')
->where('name','=',$overlay)
->execute();
$n = $query->count();
$qual = '(database table: g3_emboss_overlay)';
if($n<1) {
message::error("Internal error... $overlay missing $qual");
return;
}
if($n>1) {
message::error("Internal error... $overlay has multiple entries $qual");
return;
}
$overlay_id = $query[0]->id;
$q = db::build()
->from('emboss_overlays')
->where('id','=',$overlay_id)
->delete()
->execute();
@unlink(VARPATH . 'modules/emboss/' . $overlay);
$query = db::build()
->update('emboss_mappings')
->where('cur_overlay_id','=',$overlay_id)
->set('cur_overlay_id',-1)
->execute();
$query = db::build()
->update('emboss_mappings')
->where('best_overlay_id','=',$overlay_id)
->set('best_overlay_id',-1)
->execute();
emboss::success("Succesfully deleted $overlay");
emboss::evaluate_overlays();
}
public function usage_count($overlay_id)
{
$n = db::build()
->select()
->from('emboss_mappings')
->where('best_overlay_id','=',$overlay_id)
->execute()
->count();
return ($n>0 ? $n : '');
}
static function update_overlay_options($post)
{
$options = array('method','size','gravity','transparency');
foreach ($options as $option) {
module::set_var('emboss',$option,$post["$option"]);
}
db::build()->update('emboss_overlays')->set('active',0)->execute();
$activeOverlays = $post['active_overlays'];
if(is_array($activeOverlays)) {
foreach ($activeOverlays as $overlay) {
$q = ORM::factory('emboss_overlay')->where('name','=',$overlay)->find();
$q->active=1;
$q->save();
}
}
}
static function evaluate_overlays()
{
$overlays = ORM::factory('emboss_overlay')->where('active','=',1)->find_all();
$images = ORM::factory('item')->where('type','=','photo')->find_all();
$n_new = 0;
$n_update = 0;
$n_none = 0;
$has_changes=0;
foreach ($images as $image) {
$overlay_id = emboss::determine_best_overlay($image,$overlays);
if($overlay_id < 0) {
$n_none++;
}
$q = ORM::factory('emboss_mapping')->where('image_id','=',$image->id)->find();
if( ! $q->loaded() ) {
if($overlay_id>0) {
$n_new++;
}
$q->image_id = $image->id;
$q->best_overlay_id = $overlay_id;
$q->cur_overlay_id = -1;
$q->cur_gravity = 'unset';
$q->cur_transparency = -1;
$q->save();
} else if($q->best_overlay_id != $overlay_id) {
if($overlay_id>0) {
$n_update++;
}
$q->best_overlay_id = $overlay_id;
$q->save();
}
}
if($n_none) {
emboss::info('Cannot find an overlay for '.$n_none . t2(' image',' images'));
}
if($n_new) {
emboss::info($n_new . t2(' image needs',' images need',$n_new) .
' now have an overlay available');
}
if($n_update) {
emboss::info(t2('This changes the overlay for 1 image',
"This changes the overlay for $n_update images",
$n_update));
}
if($n_none || $n_new || $n_update) {
} else{
message::info('All photos are being embossed with the correct overlay');
}
}
static function determine_best_overlay($image,$overlays=NULL)
{
if(!$overlays) {
$overlays = ORM::factory('emboss_overlay')->where('active','=',1)->find_all();
}
$method = module::get_var('emboss','method');
$size = 0.01 * module::get_var('emboss','size');
$W = $size * $image->width;
$H = $size * $image->height;
$bestID = -1;
$bestScore=0;
foreach ($overlays as $overlay) {
$score = $overlay->score($W,$H,$method);
if ( $score>0 && $score>$bestScore ) {
$bestScore = $score;
$bestID = $overlay->id;
}
}
return $bestID;
}
static function check_for_dirty()
{
$q = emboss::find_dirty();
$n = $q->count();
if($n>0) {
$url = url::site('admin/maintenance/start/emboss_task::update_overlays?csrf=__CSRF__');
site_status::warning(
t2("One of your photos needs to be (re)embossed. <a %attrs>Click here to fix it</a>",
"%count of your photos need to be (re)embossed. <a %attrs>Click here to fix them</a>",
$n,
array('attrs' => html::mark_clean(sprintf('href="%s" class="g-dialog-link"',$url)))),
'emboss_dirty');
} else {
site_status::clear('emboss_dirty');
}
}
public function find_dirty()
{
$gravity = module::get_var('emboss','gravity');
$transparency = module::get_var('emboss','transparency');
$q = db::build()
->select()
->from('emboss_mappings')
->or_where('cur_overlay_id','!=',db::expr('best_overlay_id'))
->or_where('cur_gravity','!=',$gravity)
->or_where('cur_transparency','!=',$transparency)
->execute();
return $q;
}
public function uninstall()
{
$items = ORM::factory('item')->find_all();
foreach($items as $item) {
$path = $item->file_path() . $name;
$orig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$path);
if(file_exists($orig)) {
@unlink($path);
@rename($orig,$path);
}
}
graphics::mark_dirty(1,1);
Database::instance()->query('DROP TABLE {emboss_overlays}');
Database::instance()->query('DROP TABLE {emboss_mappings}');
Database::instancs()->query("delete from {modules} where name='emboss'");
log::info('emboss','module uninstalled (database dropped/overlays removed)');
}
}

View File

@ -0,0 +1,121 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class emboss_event_Core {
static function admin_menu($menu,$theme) {
module::set_var('emboss','admin_menu',1);
$menu->get('content_menu')
->append(
Menu::factory('link')
->id('emboss')
->label(t('Emboss'))
->url(url::site('admin/emboss')));
}
static function item_moved($item,$olddir)
{
if( ! ($item->is_photo() || $item->is_album()) ) {
return;
}
$name = $item->name;
$old_path = $olddir->file_path() . '/' . $name;
$new_path = $item->file_path();
if( $new_path == $old_path) {
return;
}
$old_orig = str_replace(VARPATH . 'albums/', VARPATH . 'originals/', $old_path);
$new_orig = str_replace(VARPATH . 'albums/', VARPATH . 'originals/', $new_path);
$new_dir = str_replace('/'.$name , '',$new_orig);
if( file_exists($old_orig))
{
emboss::mkdir_recursive($new_dir);
@rename($old_orig,$new_orig);
log::info('emboss','Moved '.$item->name.' to '.str_replace(VARPATH,'',$new_dir));
}
}
static function item_updated($original,$item)
{
if( ! ($item->is_photo() || $item->is_album()) ) {
return;
}
$oldpath = $original->file_path();
$newpath = $item->file_path();
if( $oldpath != $newpath ) {
$oldorig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$oldpath);
$neworig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$newpath);
log::info('emboss',"rename $oldorig to $neworig");
@rename($oldorig,$neworig);
}
}
static function item_deleted($item)
{
if( ! $item->is_photo() ) {
return;
}
$name = $item->name;
$id = $item->id;
$path = $item->file_path();
$orig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$path);
@unlink($orig);
db::build()
->from('emboss_mappings')
->where('image_id','=',$id)
->delete()
->execute();
log::info('emboss',"item_deleted: $name");
}
static function item_created($item)
{
if( ! $item->is_photo() ) {
return;
}
$path = $item->file_path();
$dirs = explode('/',$path);
array_pop($dirs);
$dir = implode('/',$dirs);
$orig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$path);
$origdir = str_replace(VARPATH.'albums/',VARPATH.'originals/',$dir);
emboss::mkdir_recursive($origdir);
@copy($path,$orig);
$q = ORM::factory('emboss_mapping');
$q->image_id = $item->id;
$q->best_overlay_id = emboss::determine_best_overlay($item);
$q->cur_overlay_id = -1;
$q->cur_gravity = '';
$q->cur_transparency = -1;
$q->save();
emboss::check_for_dirty();
}
}

View File

@ -0,0 +1,67 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class emboss_installer {
static function install() {
$db = Database::instance();
$db->query("CREATE TABLE IF NOT EXISTS {emboss_overlays} (
`id` int(9) NOT NULL auto_increment,
`active` tinyint(4) NOT NULL DEFAULT 1,
`name` varchar(64) NOT NULL,
`width` int(9) NOT NULL,
`height` int(9) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY(`name`))");
$db->query("CREATE TABLE IF NOT EXISTS {emboss_mappings} (
`id` int(9) NOT NULL auto_increment,
`image_id` int(9) NOT NULL,
`best_overlay_id` int(9) NOT NULL,
`cur_overlay_id` int(9),
`cur_gravity` varchar(16),
`cur_transparency` tinyint(4),
PRIMARY KEY (`id`),
UNIQUE KEY(`image_id`))");
@mkdir(VARPATH . 'originals');
@mkdir(VARPATH . 'modules');
@mkdir(VARPATH . 'modules/emboss');
module::set_version('emboss',1);
log::success('emboss','Emboss Installed');
}
static function upgrade($version)
{
module::set_version('emboss',$verion=1);
log::info('emboss',"Upgrade to version $version / No action taken");
}
static function activate()
{
log::info('emboss','Emboss Activated');
emboss::reconcile();
}
static function deactivate()
{
log::info('emboss','Emboss Deactivated');
}
static function uninstall() {
emboss::uninstall();
}
}

View File

@ -0,0 +1,150 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class emboss_task_Core {
static function available_tasks() {
$q = emboss::find_dirty();
$n = $q->count();
$description = ( ($n==0)
? (t('All photo overlays are up to date') )
: t2('one Photo needs its emboss overlay updated',
"$n Photos need their emboss overlay updated", $n) );
$tasks[] = Task_Definition::factory()
->callback('emboss_task::update_overlays')
->name(t('Update photo embossing'))
->description($description)
->severity($n>0 ? log::WARNING : log::SUCCESS);
return $tasks;
}
static function update_overlays($task)
{
$errors = array();
try {
$mode = $task->get('mode','init');
switch($mode) {
case 'init':
$q = emboss::find_dirty();
foreach ($q as $item) {
$ids[] = array('id'=>$item->id,
'image_id'=>$item->image_id,
'overlay_id'=>$item->best_overlay_id);
}
$count = count($ids);
if($count>0) {
$task->set('ids',$ids);
$task->set('count',$count);
$task->set('current',0);
$task->set('mode','continue');
} else {
$task->done = true;
$task->state = 'success';
$task->percent_complete = 100;
site_status::clear('emboss_dirty');
return;
}
break;
case 'continue':
$ids = $task->get('ids');
$count = $task->get('count');
$current = $task->get('current');
break;
}
$i = 1*$current;
$id = $ids[$i];
$current++;
$task->set('current',$current);
emboss_task::do_embossing($id['id'],$id['image_id'],$id['overlay_id']);
if($current>=$count) {
$task->done = true;
$task->state = 'success';
$task->percent_complete = 100;
$task->status = 'Complete';
site_status::clear('emboss_dirty');
} else {
$task->percent_complete = $current/$count * 100;
$task->status = t("Reembossed $current of $count photos");
}
} 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);
}
}
static function do_embossing($id,$image_id,$overlay_id)
{
$gravity = module::get_var('emboss','gravity');
$transparency = module::get_var('emboss','transparency');
$item = ORM::factory('item')->where('id','=',$image_id)->find();
$path = $item->file_path() . $name;
$orig = str_replace(VARPATH.'albums/',VARPATH.'originals/',$path);
@unlink($path);
if($overlay_id<0) {
log::info('emboss','Remove embossing from '.$item->name);
@copy($orig,$path);
} else {
$overlay = ORM::factory('emboss_overlay')->where('id','=',$overlay_id)->find();
$overlay_path = VARPATH.'modules/emboss/'.$overlay->name;
$opts['file'] = $overlay_path;
$opts['position'] = $gravity;
$opts['transparency'] = 100-$transparency;
log::info('emboss','Embossing '.$item->name.' with '.$overlay->name);
gallery_graphics::composite($orig,$path,$opts);
}
$item->thumb_dirty = 1;
$item->resize_dirty = 1;
$item->save();
graphics::generate($item);
db::build()->update('emboss_mappings')
->where('id','=',$id)
->set('cur_overlay_id',$overlay_id)
->set('cur_gravity',$gravity)
->set('cur_transparency',$transparency)
->execute();
}
}

View File

@ -0,0 +1,3 @@
<?php defined('SYSPATH') or die('No direct script access.');
class Emboss_Mapping_Model_Core extends ORM {
}

View File

@ -0,0 +1,83 @@
<?php defined('SYSPATH') or die('No direct script access.');
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
class Emboss_Overlay_Model_Core extends ORM {
protected $sorting = array('width' => 'desc', 'height' => 'desc');
public function score($W,$H,$function)
{
/*************************************************************
* (W,H) = Image (Width,Height)
* (w,h) = Overlay (width,height)
*************************************************************/
$w = $this->width;
$h = $this->height;
if( ($w>$W) || ($h>$H) ) { return 0; }
/*************************************************************
* Minimize Margin Method
*************************************************************
* Score = (W^2 + H^2) - ((W-w)^2 + (H-h)^2)
* = (W^2 - (W-w)^2) + (H^2 - (H-h)^2)
* = (2Ww - w^2) + (2Hh - h^2)
* = (2W-w)w + (2H-h)h
*************************************************************/
if($function == 'margin') {
$score = ( (2*$W - $w)*$w + (2*$H - $h)*$h );
}
/*************************************************************
* Aspect Ratio Weighted
*************************************************************
* if h < w*(H/W)
* peak value = area on diagonal (w*h)
* null value = 0 on w axis (h=0)
* quadratic fit between:
* Score = W/H h^2
* if w < h*(W/H)
* Score = H/W w^2 (by symmetry)
*************************************************************/
else if($function == 'diag') {
if($h*$W < $w*$H) {
$score = $h*$h*($W/$H);
} else {
$score = $w*$w*($H/$W);
}
}
/*************************************************************
* Area Method (Default if no match to $function)
*************************************************************
* Score = w * h
*************************************************************/
else {
$score = $w * $h;
}
return $score;
}
public function area()
{
return $this->width * $this->height;
}
}

View File

@ -0,0 +1,7 @@
name = "Emboss"
description = "A different watermarking module"
version = 1
author_name = "mikemayer67"
author_url = "http://www.vmwishes.com"
info_url = "http://codex.gallery2.org/Gallery3:Modules:emboss"
discuss_url = "http://gallery.menalto.com/node/105339"

View File

@ -0,0 +1,125 @@
<?php defined('SYSPATH') or die('No direct script access.') ?>
/*************************************************************************
* Copyright (C) 2012 Michel A. Mayer *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
<script language="JavaScript">
function checkAllOverlays()
{
with(document.options) {
for(var i=0; i<elements.length; i++) {
if(elements[i].type=='checkbox' && elements[i].name=='active_overlays[]') {
elements[i].checked = true;
}
}
}
}
function uncheckAllOverlays()
{
with(document.options) {
for(var i=0; i<elements.length; i++) {
if(elements[i].type=='checkbox' && elements[i].name=='active_overlays[]') {
elements[i].checked = false;
}
}
}
}
</script>
<hr>
<div>
<h2>Upload New Overlay</h2>
<?=form::open_multipart('admin/emboss/new_overlay')?>
<?=access::csrf_form_field()?>
<?=form::upload(array('name'=>'overlay','style'=>'margin: .5em 0 .5em 0'))?>
<?=form::submit(array('name'=>'Upload','style'=>'display:block; float:none'),'Upload')?>
</form>
</div>
<hr>
<div>
<?=form::open('admin/emboss/update',array('name'=>'options'))?>
<?=access::csrf_form_field()?>
<h2>Available Overlays</h2>
<table style="margin:.5em 0 .5em 0">
<tr>
<th style>Active</th>
<th>Image</th>
<th>Size</th>
<th>Usage</th>
<th></th>
</tr>
<?php foreach ($images as $image):
$data['name'] = 'active_overlays[]';
$data['value'] = $image->name;
$data['checked'] = $image->active;
?>
<tr class="<?=text::alternate('g-odd','g-even')?>">
<td><?=form::checkbox($data,1)?></td>
<td><?=$image->name?></td>
<td><?=$image->width?> x <?=$image->height?></td>
<td><?=emboss::usage_count($image->id)?></td>
<td><?=html::anchor('admin/emboss/delete_overlay?name='.$image->name.'&csrf='.access::csrf_token(), 'delete')?></td></tr>
<? endforeach ?>
<tr class="<?=text::alternate('g-odd','g-even')?>"><td colspan=5>
<a href='javascript:checkAllOverlays()'>Check All</a> /
<a href='javascript:uncheckAllOverlays()'>Uncheck All</a>
</td></tr>
</table>
<?=form::submit(array('name'=>'Update','style'=>'display:block; float:none'),'Update')?>
<div style="margin:.5cm 0 .5cm 0">
<h2>Embossing Parameters</h2>
<table style="margin:.5em 0 .5em 0">
<tr><th></th><th></th></tr>
<tr class="<?=text::alternate('g-odd','g-even')?>">
<td style="width:15; text-align:right">Best Fit Method:</td>
<td style="width:85%"><?= form::dropdown('method',array('area' =>'Maximum Overlay Area',
'margin'=>'Minimize Borders',
'diag' =>'Aspect Ratio Weighted'),
module::get_var('emboss','method','area')) ?></td></tr>
<tr class="<?=text::alternate('g-odd','g-even')?>">
<td style="width:15; text-align:right">Location:</td>
<td style="width:85%"><?=form::dropdown('gravity',array('northwest' => 'Northwest',
'north' => 'North',
'northeast' => 'Northeast',
'east' => 'East',
'southeast' => 'Southeast',
'south' => 'South',
'southwest' => 'Southwest',
'south' => 'South',
'center' => 'Center'),
module::get_var('emboss','gravity','Center')) ?></td></tr>
<?php for($i=100; $i>0; $i-=5) { $sizes["$i"]="$i%"; } ?>
<?php for($i=0; $i<100; $i+=10) { $transparencies["$i"]="$i%"; } ?>
<tr class="<?=text::alternate('g-odd','g-even')?>">
<td style="width:15; text-align:right">Desired Size:</td>
<td style="width:85%"><?=form::dropdown('size',$sizes,
module::get_var('emboss','size',85)) ?></td></tr>
<tr class="<?=text::alternate('g-odd','g-even')?>">
<td style="width:15; text-align:right">Transparency:</td>
<td style="width:85%"><?=form::dropdown('transparency',$transparencies,
module::get_var('emboss','transparency',50)) ?></td></tr>
</table>
</div>
<?=form::submit(array('name'=>'Update','style'=>'display:block; float:none'),'Update')?> </form>
</div>
<hr>
<div style="margin:.5cm 0 0 0">
<a href="<?= url::site('admin/emboss/clear_log') ?>"
title="<?= t('Clear Emboss Log Entries')->for_html_attr() ?>"
class="g-button ui-icon-left ui-state-default ui-corner-all">
<?= t('Clear Emboss Log Entries') ?>
</a>
</div>

View File

@ -1,12 +1,17 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-social_share-google">
<!-- Place this tag where you want the +1 button to render -->
<div class="g-plusone"" size="<?= module::get_var("social_share", "google_size") ?>" annotation="<?= module::get_var("social_share", "google_annotation") ?>"></div>
<div class="g-plusone""
size="<?= module::get_var("social_share", "google_size") ?>"
annotation="<?= module::get_var("social_share", "google_annotation") ?>">
</div>
<!-- Place this render call where appropriate -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
var po = document.createElement('script');
po.type = 'text/javascript';
x2po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();

View File

@ -1,5 +1,21 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div class="g-social_share-twitter_tweet">
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="en" data-size="<?= module::get_var("social_share", "twitter_size") ?>" data-count="<?= module::get_var("social_share", "twitter_count_location") ?>">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<a href="https://twitter.com/share"
class="twitter-share-button"
data-lang="en"
data-size="<?= module::get_var("social_share", "twitter_size") ?>"
data-count="<?= module::get_var("social_share", "twitter_count_location") ?>">
Tweet
</a>
<script>!function(d,s,id)
{ var js,fjs=d.getElementsByTagName(s)[0];
if(!d.getElementById(id))
{ js=d.createElement(s);
js.id=id;
js.src="//platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js,fjs);
}
}
(document,"script","twitter-wjs");
</script>
</div>