private function _doThumbOf($file, $newFile, $params)
{
if ($file instanceof Image) {
$this->_image = $file;
} else {
if (!is_file($file)) {
return false;
}
$this->_image = Image::factory($this->detectPath($file), $this->driver, $this->isProgressiveJpeg);
}
foreach ($params as $key => $value) {
switch ($key) {
case 'resize':
$this->resize(isset($value['width']) ? $value['width'] : null, isset($value['height']) ? $value['height'] : null, isset($value['master']) ? $value['master'] : null);
break;
case 'crop':
if (!isset($value['width']) || !isset($value['height'])) {
throw new CException('Params "width" and "height" is required for action "' . $key . '"');
}
$this->crop($value['width'], $value['height'], isset($value['offset_x']) ? $value['offset_x'] : null, isset($value['offset_y']) ? $value['offset_y'] : null);
break;
case 'scaleAndCrop':
$this->scaleAndCrop($value['width'], $value['height']);
break;
case 'rotate':
if (is_array($value)) {
if (!isset($value['degrees'])) {
throw new CException('Param "degrees" is required for action "' . $key . '"');
}
$this->rotate($value['degrees']);
} else {
$this->rotate($value);
}
break;
case 'flip':
if (is_array($value)) {
if (!isset($value['direction'])) {
throw new CException('Param "direction" is required for action "' . $key . '"');
}
$this->flip($value['direction']);
} else {
$this->flip($value);
}
break;
case 'sharpen':
if (is_array($value)) {
if (!isset($value['amount'])) {
throw new CException('Param "amount" is required for action "' . $key . '"');
}
$this->sharpen($value['amount']);
} else {
$this->sharpen($value);
}
break;
case 'reflection':
$this->reflection(isset($value['height']) ? $value['height'] : null, isset($value['opacity']) ? $value['opacity'] : 100, isset($value['fade_in']) ? $value['fade_in'] : false);
break;
case 'watermark':
if (is_array($value)) {
$this->watermark(isset($value['watermark']) ? $value['watermark'] : null, isset($value['offset_x']) ? $value['offset_x'] : null, isset($value['offset_y']) ? $value['offset_y'] : null, isset($value['opacity']) ? $value['opacity'] : 100);
} else {
$this->watermark($value);
}
break;
case 'background':
if (is_array($value)) {
if (!isset($value['color'])) {
throw new CException('Param "color" is required for action "' . $key . '"');
}
$this->background($value['color'], isset($value['opacity']) ? $value['opacity'] : 100);
} else {
$this->background($value);
}
break;
case 'quality':
if (!isset($value)) {
throw new CException('Param "' . $key . '" can\'t be empty');
}
$this->quality = $value;
break;
case 'type':
break;
default:
throw new CException('Action "' . $key . '" is not found');
}
}
$result = $this->save($newFile, $this->quality);
@chmod($newFile, $this->newFileMode);
return $result;
}