*/ /** * This ItemAddOption uses the size limit values and resizes * gallery item when the image is uploaded. * * @package SizeLimit * @subpackage UserInterface */ GalleryCoreApi::requireOnce('modules/sizelimit/classes/SizeLimitHelper.class'); class SetSizeOption extends ItemAddOption { /** * @see ItemAddOption::isAppropriate */ function isAppropriate() { return array(null, true); } /** * @see ItemAddOption::handleRequestAfterAdd */ function handleRequestAfterAdd($form, $items) { $errors = array(); $warnings = array(); list ($ret, $module) = GalleryCoreApi::loadPlugin('module', 'sizelimit'); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } for ($i = 0; $i < count($items); $i++) { $warnings[$i] = array(); if (!GalleryUtilities::isA($items[$i], 'GalleryDataItem')) { continue; } list ($ret, $param) = GalleryCoreApi::fetchAllPluginParameters( 'module', 'sizelimit', $items[$i]->getParentId()); if ($ret) { return array($ret->wrap(__FILE__, __LINE__), null, null); } $param = array_merge( array('keepOriginal' => 0, 'width' => 0, 'height' => 0, 'size' => 0), $param); if ($param['width'] && $param['height'] && method_exists($items[$i], 'getwidth') && method_exists($items[$i], 'getheight') && ($items[$i]->getWidth() > $param['width'] || $items[$i]->getHeight() > $param['height'])) { $args = array($param['width'], $param['height']); if ($param['keepOriginal']) { $ret = SizeLimitHelper::buildDerivativeWithLimits($items[$i], 'scale', $args); } else { $ret = SizeLimitHelper::applyLimits($items[$i], 'scale', $args); } if ($ret) { if ($ret->getErrorCode() & ERROR_UNSUPPORTED_FILE_TYPE) { $warnings[$i][] = $module->translate( array('text' => 'WARNING: Cannot resize mime type %s', 'arg1' => $items[$i]->getMimeType())); } else { return array($ret->wrap(__FILE__, __LINE__), null, null); } } } if (isset($param['size']) && $param['size'] > 0 && ($items[$i]->getSize() >> 10) > $param['size']) { $args = array($param['size']); if ($param['keepOriginal']) { $ret = SizeLimitHelper::buildDerivativeWithLimits($items[$i], 'compress', $args); } else { $ret = SizeLimitHelper::applyLimits($items[$i], 'compress', $args); } if ($ret) { if ($ret->getErrorCode() & ERROR_UNSUPPORTED_FILE_TYPE) { $warnings[$i][] = $module->translate( array('text' => 'WARNING: Cannot compress mime type %s', 'arg1' => $items[$i]->getMimeType())); } else { return array($ret->wrap(__FILE__, __LINE__), null, null); } } } } return array(null, $errors, $warnings); } } ?>