5 class Resize extends \Rsi\Fred\Stream\Handler{
7 public $mode = IMG_BILINEAR_FIXED;
20 protected function index($sizes,&$size,$other_sizes = null,&$other_size = null){
23 foreach($sizes as $index => $size){
24 if($this->locked && $other_sizes) $other_size = \Rsi\Record::get($other_sizes,$index);
25 if($size >= $ref)
break;
37 protected function dimensions($orig_width,$orig_height,&$new_width,&$new_height){
38 $this->
index($this->widths,$new_width,$this->heights,$new_height);
39 if(!$new_height) $new_height = intdiv($orig_height * $new_width,$orig_width);
40 $this->
index($this->heights,$new_height,$this->widths,$new_width);
41 if(!$new_width) $new_width = intdiv($orig_width * $new_height,$orig_height);
45 $data = parent::read(
$handlers,$filename,$params);
46 $new_width = \Rsi\Record::get($params,
'width');
47 $new_height = \Rsi\Record::get($params,
'height');
48 if(($new_width || $new_height) && ($orig_image = imagecreatefromstring($data))){
49 $this->
dimensions(imagesx($orig_image),imagesy($orig_image),$new_width,$new_height);
50 $new_image = imagescale($orig_image,$new_width,$new_height,$this->mode);
51 imagedestroy($orig_image);
53 switch(\
Rsi\File::ext($filename)){
54 case 'gif': imagegif($new_image);
break;
55 case 'png': imagepng($new_image);
break;
56 default: imagejpeg($new_image,null,$this->jpegQuality);
58 $data = ob_get_clean();
59 imagedestroy($new_image);
index($sizes, &$size, $other_sizes=null, &$other_size=null)
Pick the next larger value from an array.
$locked
Allowed sizes will be locked together by key.
read($handlers, $filename, $params=null)
$widths
Allowed widths (small to large; empty = all).
dimensions($orig_width, $orig_height, &$new_width, &$new_height)
Calculate the dimensions for the image.
$heights
Allowed heights (small to large; empty = all).