Skip to content

Commit

Permalink
JIT image process is it's own Symphony renderer
Browse files Browse the repository at this point in the history
Just a commit of everything locally, don't think this works at all yet

Rebased version of 3b04a03

Switch to semver: Fixes #104
  • Loading branch information
brendo authored and nitriques committed Mar 22, 2016
1 parent 671a199 commit ef9351a
Show file tree
Hide file tree
Showing 15 changed files with 1,221 additions and 274 deletions.
29 changes: 27 additions & 2 deletions extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,35 @@ public function getSubscribedDelegates(){
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => '__SavePreferences'
),
array(
'page' => '/all/',
'delegate' => 'ModifySymphonyLauncher',
'callback' => 'modifySymphonyLauncher'
)
);
}

public function modifySymphonyLauncher($context) {
if ($_REQUEST['mode'] !== 'jit') {
return;
}

function jit_launcher($mode) {
if (strtolower($mode) == 'jit') {
require_once __DIR__ . '/lib/class.jit.php';

$renderer = JIT\JIT::instance();
$renderer->display();
}
else {
symphony_launcher($mode);
}
}

define('SYMPHONY_LAUNCHER', 'jit_launcher');
}

public function install() {
require_once 'lib/class.htaccess.php';
$htaccess = new HTAccess();
Expand Down Expand Up @@ -426,7 +451,7 @@ public function appendPreferences($context){
if (Symphony::Configuration()->get('disable_upscaling', 'image') == 'yes') $input->setAttribute('checked', 'checked');
$label->setValue($input->generate() . ' ' . __('Disable upscaling of images beyond the original size'));
$group->appendChild($label);

// checkbox to diable proxy transformation of images
$label = Widget::Label();
$input = Widget::Input('settings[image][disable_proxy_transform]', 'yes', 'checkbox');
Expand Down Expand Up @@ -460,7 +485,7 @@ public function __SavePreferences($context){
if (!isset($context['settings']['image']['disable_upscaling'])) {
$context['settings']['image']['disable_upscaling'] = 'no';
}

if (!isset($context['settings']['image']['disable_proxy_transform'])) {
$context['settings']['image']['disable_proxy_transform'] = 'no';
}
Expand Down
3 changes: 3 additions & 0 deletions extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
</author>
</authors>
<releases>
<release version="2.0.0" date="2016-03-21" min="2.6.0" max="2.x.x">
- JIT image process is it's own Symphony renderer now
</release>
<release version="1.45" date="2016-03-21" min="2.6.0" max="2.x.x">
- Add CORS header support (@tmslnz)
- Added 'max-age' hidden configuration
Expand Down
165 changes: 165 additions & 0 deletions filters/filter.crop.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

Class FilterCrop extends JIT\ImageFilter{

public $mode = 3;

const TOP_LEFT = 1;
const TOP_MIDDLE = 2;
const TOP_RIGHT = 3;
const MIDDLE_LEFT = 4;
const CENTER = 5;
const MIDDLE_RIGHT = 6;
const BOTTOM_LEFT = 7;
const BOTTOM_MIDDLE = 8;
const BOTTOM_RIGHT = 9;

public static function about() {
return array(
'name' => 'JIT Filter: Crop'
);
}



public static function parseParameters($parameter_string)
{
$param = array();

if(preg_match_all('/^(2|3)\/([0-9]+)\/([0-9]+)\/([1-9])\/([a-fA-F0-9]{3,6}\/)?(?:(0|1)\/)?(.+)$/i', $parameter_string, $matches, PREG_SET_ORDER)){
$param['mode'] = (int)$matches[0][1];
$param['settings']['width'] = (int)$matches[0][2];
$param['settings']['height'] = (int)$matches[0][3];
$param['settings']['position'] = (int)$matches[0][4];
$param['settings']['background'] = trim($matches[0][5],'/');
$param['settings']['external'] = (bool)$matches[0][6];
$param['image_path'] = $matches[0][7];
}

return !empty($param) ? $param : false;
}

public static function run(\Image $res, $settings) { //$width, $height, $anchor=self::TOP_LEFT, $background_fill = null){

$dst_w = Image::width($res);
$dst_h = Image::height($res);

if(!empty($width) && !empty($height)) {
$dst_w = $width;
$dst_h = $height;
}
else if(empty($height)) {
$ratio = ($dst_h / $dst_w);
$dst_w = $width;
$dst_h = round($dst_w * $ratio);
}
else if(empty($width)) {
$ratio = ($dst_w / $dst_h);
$dst_h = $height;
$dst_w = round($dst_h * $ratio);
}

$tmp = imagecreatetruecolor($dst_w, $dst_h);

self::__fill($res, $tmp, $background_fill);

list($src_x, $src_y, $dst_x, $dst_y) = self::__calculateDestSrcXY($dst_w, $dst_h, Image::width($res), Image::height($res), Image::width($res), Image::height($res), $anchor);

imagecopyresampled($tmp, $res, $src_x, $src_y, $dst_x, $dst_y, Image::width($res), Image::height($res), Image::width($res), Image::height($res));

if(is_resource($res)) {
imagedestroy($res);
}

return $tmp;
}

protected static function __calculateDestSrcXY($width, $height, $src_w, $src_h, $dst_w, $dst_h, $position=self::TOP_LEFT){

$dst_x = $dst_y = 0;
$src_x = $src_y = 0;

if($width < $src_w){
$mx = array(
0,
ceil(($src_w * 0.5) - ($width * 0.5)),
$src_x = $src_w - $width
);
}

else{
$mx = array(
0,
ceil(($width * 0.5) - ($src_w * 0.5)),
$src_x = $width - $src_w
);
}

if($height < $src_h){
$my = array(
0,
ceil(($src_h * 0.5) - ($height * 0.5)),
$src_y = $src_h - $height
);
}

else{

$my = array(
0,
ceil(($height * 0.5) - ($src_h * 0.5)),
$src_y = $height - $src_h
);
}

switch($position){

case 1:
break;

case 2:
$src_x = 1;
break;

case 3:
$src_x = 2;
break;

case 4:
$src_y = 1;
break;

case 5:
$src_x = 1;
$src_y = 1;
break;

case 6:
$src_x = 2;
$src_y = 1;
break;

case 7:
$src_y = 2;
break;

case 8:
$src_x = 1;
$src_y = 2;
break;

case 9:
$src_x = 2;
$src_y = 2;
break;

}

$a = ($width >= $dst_w ? $mx[$src_x] : 0);
$b = ($height >= $dst_h ? $my[$src_y] : 0);
$c = ($width < $dst_w ? $mx[$src_x] : 0);
$d = ($height < $dst_h ? $my[$src_y] : 0);

return array($a, $b, $c, $d);
}
}
75 changes: 75 additions & 0 deletions filters/filter.resize.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

Class FilterResize extends JIT\ImageFilter {

public $mode = 1;

public static function about() {
return array(
'name' => 'JIT Filter: Resize'
);
}

public static function parseParameters($parameter_string)
{
$param = array();

if(preg_match_all('/^(1|4)\/([0-9]+)\/([0-9]+)\/(?:(0|1)\/)?(.+)$/i', $parameter_string, $matches, PREG_SET_ORDER)){
$param['mode'] = (int)$matches[0][1];
$param['settings']['width'] = (int)$matches[0][2];
$param['settings']['height'] = (int)$matches[0][3];
$param['settings']['external'] = (bool)$matches[0][4];
$param['image_path'] = $matches[0][5];
}

if(preg_match_all('/^(2|3)\/([0-9]+)\/([0-9]+)\/([1-9])\/([a-fA-F0-9]{3,6}\/)?(?:(0|1)\/)?(.+)$/i', $parameter_string, $matches, PREG_SET_ORDER)){
$param['mode'] = (int)$matches[0][1];
$param['settings']['width'] = (int)$matches[0][2];
$param['settings']['height'] = (int)$matches[0][3];
$param['settings']['position'] = (int)$matches[0][4];
$param['settings']['background'] = trim($matches[0][5],'/');
$param['settings']['external'] = (bool)$matches[0][6];
$param['image_path'] = $matches[0][7];
}

return !empty($param) ? $param : false;
}

public static function run(\Image $res, $settings) {

$dst_w = Image::width($res);
$dst_h = Image::height($res);

if(!empty($width) && !empty($height)) {
$dst_w = $width;
$dst_h = $height;
}

elseif(empty($height)) {
$ratio = ($dst_h / $dst_w);
$dst_w = $width;
$dst_h = round($dst_w * $ratio);
}

elseif(empty($width)) {

$ratio = ($dst_w / $dst_h);
$dst_h = $height;
$dst_w = round($dst_h * $ratio);

}

$dst = imagecreatetruecolor($dst_w, $dst_h);

self::__fill($res, $dst);

imagecopyresampled($dst, $res, 0, 0, 0, 0, $dst_w, $dst_h, Image::width($res), Image::height($res));

if(is_resource($res)) {
imagedestroy($res);
}

return $dst;

}
}
Loading

0 comments on commit ef9351a

Please sign in to comment.