Changeset 12851 for trunk/admin
- Timestamp:
- Jan 5, 2012, 10:35:25 PM (12 years ago)
- Location:
- trunk/admin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/derivatives.php
r12820 r12851 29 29 { 30 30 $pderivatives = $_POST['d']; 31 $pwatermark = $_POST['w']; 31 32 32 33 // step 1 - sanitize HTML input … … 87 88 $prev_h = intval($pderivative['h']); 88 89 } 89 } 90 91 $v = intval($pderivative['sharpen']); 92 if ($v<0 || $v>100) 93 { 94 $errors[$type]['sharpen'] = '[0..100]'; 95 } 96 $v = intval($pderivative['quality']); 97 if ($v<=0 || $v>100) 98 { 99 $errors[$type]['quality'] = '(0..100]'; 100 } 101 } 102 $v = intval($pwatermark['xpos']); 103 if ($v<0 || $v>100) 104 { 105 $errors['watermark']['xpos'] = '[0..100]'; 106 } 107 $v = intval($pwatermark['ypos']); 108 if ($v<0 || $v>100) 109 { 110 $errors['watermark']['ypos'] = '[0..100]'; 111 } 112 $v = intval($pwatermark['opacity']); 113 if ($v<=0 || $v>100) 114 { 115 $errors['watermark']['opacity'] = '(0..100]'; 116 } 117 118 90 119 // step 3 - save data 91 120 if (count($errors)==0) 92 121 { 122 $watermark = new WatermarkParams(); 123 $watermark->file = $pwatermark['file']; 124 $watermark->xpos = intval($pwatermark['xpos']); 125 $watermark->ypos = intval($pwatermark['ypos']); 126 $watermark->xrepeat = intval($pwatermark['xrepeat']); 127 $watermark->opacity = intval($pwatermark['opacity']); 128 $watermark->min_size = array(intval($pwatermark['minw']),intval($pwatermark['minh'])); 129 130 $old_watermark = ImageStdParams::get_watermark(); 131 $watermark_changed = 132 $watermark->file != $old_watermark->file 133 || $watermark->xpos != $old_watermark->xpos 134 || $watermark->ypos != $old_watermark->ypos 135 || $watermark->xrepeat != $old_watermark->xrepeat 136 || $watermark->opacity != $old_watermark->opacity; 137 ImageStdParams::set_watermark($watermark); 138 93 139 $enabled = ImageStdParams::get_defined_type_map(); 94 140 $disabled = @unserialize( @$conf['disabled_derivatives'] ); … … 107 153 $new_params = new DerivativeParams( 108 154 new SizingParams( 109 array( $pderivative['w'],$pderivative['h']),155 array(intval($pderivative['w']), intval($pderivative['h'])), 110 156 round($pderivative['crop'] / 100, 2), 111 array( $pderivative['minw'],$pderivative['minh'])157 array(intval($pderivative['minw']), intval($pderivative['minh'])) 112 158 ) 113 159 ); 160 $new_params->sharpen = intval($pderivative['sharpen']); 161 $new_params->quality = intval($pderivative['quality']); 162 ImageStdParams::apply_global($new_params); 163 114 164 if (isset($enabled[$type])) 115 165 { … … 124 174 if ( $same && $new_params->sizing->max_crop != 0 125 175 && !size_equals($old_params->sizing->min_size, $new_params->sizing->min_size) ) 176 { 177 $same = false; 178 } 179 180 if ( $same && 181 ( $new_params->sharpen != $old_params->sharpen 182 || $new_params->quality > $old_params->quality) 183 ) 184 { 185 $same = false; 186 } 187 188 if ($same && 189 ( $new_params->use_watermark != $old_params->use_watermark 190 || $new_params->use_watermark && $watermark_changed ) 191 ) 126 192 { 127 193 $same = false; … … 183 249 { 184 250 $template->assign('derivatives', $pderivatives); 251 $template->assign('watermark', $pwatermark); 185 252 $template->assign('ferrors', $errors); 186 253 } … … 225 292 $tpl_var['minw'] = $tpl_var['minh'] = ""; 226 293 } 294 $tpl_var['sharpen'] = $params->sharpen; 295 $tpl_var['quality'] = $params->quality; 227 296 } 228 297 $tpl_vars[$type]=$tpl_var; 229 298 } 230 299 $template->assign('derivatives', $tpl_vars); 300 301 $wm = ImageStdParams::get_watermark(); 302 $template->assign('watermark', array( 303 'file' => $wm->file, 304 'minw' => $wm->min_size[0], 305 'minh' => $wm->min_size[1], 306 'xpos' => $wm->xpos, 307 'ypos' => $wm->ypos, 308 'xrepeat' => $wm->xrepeat, 309 'opacity' => $wm->opacity, 310 )); 231 311 } 312 313 $watermark_files = array(); 314 foreach (glob(PHPWG_ROOT_PATH.'themes/default/watermarks/*.png') as $file) 315 { 316 $watermark_files[] = substr($file, strlen(PHPWG_ROOT_PATH)); 317 } 318 $watermark_filemap = array( '' => '---' ); 319 foreach( $watermark_files as $file) 320 { 321 $display = basename($file); 322 $watermark_filemap[$file] = $display; 323 } 324 $template->assign('watermark_files', $watermark_filemap); 232 325 233 326 $template->set_filename('derivatives', 'derivatives.tpl'); -
trunk/admin/include/image.class.php
r12756 r12851 42 42 43 43 function resize($width, $height); 44 45 function sharpen($amount); 46 47 function compose($overlay, $x, $y, $opacity); 44 48 45 49 function write($destination_filepath); … … 257 261 258 262 return $rotation; 263 } 264 265 /** Returns a normalized convolution kernel for sharpening*/ 266 static function get_sharpen_matrix($amount) 267 { 268 // Amount should be in the range of 18-10 269 $amount = round(abs(-18 + ($amount * 0.08)), 2); 270 271 $matrix = array 272 ( 273 array(-1, -1, -1), 274 array(-1, $amount, -1), 275 array(-1, -1, -1), 276 ); 277 278 $norm = array_sum(array_map('array_sum', $matrix)); 279 280 for ($i=0; $i<3; $i++) 281 { 282 $line = & $matrix[$i]; 283 for ($j=0; $j<3; $j++) 284 $line[$j] /= $norm; 285 } 286 287 return $matrix; 259 288 } 260 289 … … 398 427 } 399 428 429 function sharpen($amount) 430 { 431 $m = pwg_image::get_sharpen_matrix($amount); 432 return $this->image->convolveImage($m); 433 } 434 435 function compose($overlay, $x, $y, $opacity) 436 { 437 // todo 438 return false; 439 } 440 400 441 function write($destination_filepath) 401 442 { … … 416 457 var $commands = array(); 417 458 418 function __construct($source_filepath, $imagickdir='') 419 { 459 function __construct($source_filepath) 460 { 461 global $conf; 420 462 $this->source_filepath = $source_filepath; 421 $this->imagickdir = $ imagickdir;422 423 $command = $ imagickdir.'identify -format "%wx%h" "'.realpath($source_filepath).'"';463 $this->imagickdir = $conf['ext_imagick_dir']; 464 465 $command = $this->imagickdir.'identify -format "%wx%h" "'.realpath($source_filepath).'"'; 424 466 @exec($command, $returnarray); 425 467 if(!is_array($returnarray) or empty($returnarray[0]) or !preg_match('/^(\d+)x(\d+)$/', $returnarray[0], $match)) 426 468 { 427 die("[External ImageMagick] Corrupt image ");469 die("[External ImageMagick] Corrupt image\n" . var_export($returnarray, true)); 428 470 } 429 471 … … 477 519 $this->add_command('filter', 'Lanczos'); 478 520 $this->add_command('resize', $width.'x'.$height.'!'); 521 return true; 522 } 523 524 function sharpen($amount) 525 { 526 $m = pwg_image::get_sharpen_matrix($amount); 527 528 $param ='convolve "'.count($m).':'; 529 foreach ($m as $line) 530 { 531 $param .= ' '; 532 $param .= implode(',', $line); 533 } 534 $param .= '"'; 535 $this->add_command('morphology', $param); 536 return true; 537 } 538 539 function compose($overlay, $x, $y, $opacity) 540 { 541 $param = 'compose dissolve -define compose:args='.$opacity; 542 $param .= ' '.escapeshellarg(realpath($overlay->image->source_filepath)); 543 $param .= ' -gravity NorthWest -geometry +'.$x.'+'.$y; 544 $param .= ' -composite'; 545 $this->add_command($param); 479 546 return true; 480 547 } … … 497 564 $exec .= ' "'.realpath($dest['dirname']).'/'.$dest['basename'].'"'; 498 565 @exec($exec, $returnarray); 566 567 //echo($exec); 499 568 return is_array($returnarray); 500 569 } … … 612 681 } 613 682 683 function sharpen($amount) 684 { 685 $m = pwg_image::get_sharpen_matrix($amount); 686 return imageconvolution($this->image, $m, 1, 0); 687 } 688 689 function compose($overlay, $x, $y, $opacity) 690 { 691 $ioverlay = $overlay->image->image; 692 /* A replacement for php's imagecopymerge() function that supports the alpha channel 693 See php bug #23815: http://bugs.php.net/bug.php?id=23815 */ 694 695 $ow = imagesx($ioverlay); 696 $oh = imagesy($ioverlay); 697 698 // Create a new blank image the site of our source image 699 $cut = imagecreatetruecolor($ow, $oh); 700 701 // Copy the blank image into the destination image where the source goes 702 imagecopy($cut, $this->image, 0, 0, $x, $y, $ow, $oh); 703 704 // Place the source image in the destination image 705 imagecopy($cut, $ioverlay, 0, 0, 0, 0, $ow, $oh); 706 imagecopymerge($this->image, $cut, $x, $y, 0, 0, $ow, $oh, $opacity); 707 return true; 708 } 709 614 710 function write($destination_filepath) 615 711 { -
trunk/admin/themes/default/template/derivatives.tpl
r12829 r12851 24 24 25 25 <form method="post" id="derviativesForm"> 26 <fieldset> 27 <legend>{'Watermark'|@translate}</legend> 28 29 30 <select name="w[file]" id="wSelect"> 31 {html_options options=$watermark_files selected=$watermark.file} 32 </select> 33 34 <p><img id="wImg"></img></p> 35 36 <label>{'Min Width'|@translate} 37 <input type="text" name="w[minw]" value="{$watermark.minw}"{if isset($ferrors.watermark.minw)}class="dError"{/if}> 38 </label> 39 40 <label>{'Min Height'|@translate} 41 <input type="text" name="w[minh]" value="{$watermark.minh}"{if isset($ferrors.watermark.minh)}class="dError"{/if}> 42 </label> 43 44 <label>{'X Position'|@translate} 45 <input type="text" name="w[xpos]" value="{$watermark.xpos}"{if isset($ferrors.watermark.xpos)}class="dError"{/if}> 46 %</label> 47 48 <label>{'Y Position'|@translate} 49 <input type="text" name="w[ypos]" value="{$watermark.ypos}"{if isset($ferrors.watermark.ypos)}class="dError"{/if}> 50 %</label> 51 52 <label>{'X Repeat'|@translate} 53 <input type="text" name="w[xrepeat]" value="{$watermark.xrepeat}"{if isset($ferrors.watermark.xrepeat)}class="dError"{/if}> 54 </label> 55 56 <label>{'Opacity'|@translate} 57 <input type="text" name="w[opacity]" value="{$watermark.opacity}"{if isset($ferrors.watermark.opacity)}class="dError"{/if}> 58 </label> 59 60 </fieldset> 61 26 62 <table class="table2"> 27 63 <thead> … … 34 70 <td>{'Min Width'|@translate}</td> 35 71 <td>{'Min Height'|@translate}</td> 72 <td>{'Sharpen'|@translate} (%)</td> 73 <td>{'Quality'|@translate} (%)</td> 36 74 </tr> 37 75 </thead> … … 66 104 {if isset($ferrors.$type.minh)}<span class="dErrorDesc" title="{$ferrors.$type.minh}">!</span>{/if} 67 105 {/if}</td> 68 106 <td> 107 <input type="text" name="d[{$type}][sharpen]" value="{$d.sharpen}"{if isset($ferrors.$type.sharpen)}class="dError"{/if}> 108 {if isset($ferrors.$type.sharpen)}<span class="dErrorDesc" title="{$ferrors.$type.sharpen}">!</span>{/if} 109 </td> 110 <td> 111 <input type="text" name="d[{$type}][quality]" value="{$d.quality}"{if isset($ferrors.$type.quality)}class="dError"{/if}> 112 {if isset($ferrors.$type.quality)}<span class="dErrorDesc" title="{$ferrors.$type.quality}">!</span>{/if} 113 </td> 69 114 </tr> 70 115 {/foreach} … … 77 122 jQuery(this).removeClass("dError"); 78 123 } ); 124 125 function onWatermarkChange() 126 { 127 var val = jQuery("#wSelect").val(); 128 if (val.length) { 129 jQuery("#wImg").attr('src', {/literal}'{$ROOT_URL}'{literal}+val).show(); 130 } 131 else { 132 jQuery("#wImg").hide(); 133 } 134 } 135 136 onWatermarkChange(); 137 jQuery("#wSelect").bind("change", onWatermarkChange ); 79 138 {/literal}{/footer_script}
Note: See TracChangeset
for help on using the changeset viewer.