示例#1
0
}
$src = $_REQUEST['src'];
$width = $_REQUEST['width'];
$dest = $_REQUEST['dest'];
// Load necessary Joomla libraries
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.folder');
// Load image manipulation library
require_once JPATH_ROOT . DS . 'plugins' . DS . 'system' . DS . 'jsnmobilize' . DS . 'libraries' . DS . '3rd-party' . DS . 'ace-media-image' . DS . 'image.php';
// Resize the original image to requested width
$image = new Ace_Media_Image($_SERVER['DOCUMENT_ROOT'] . DS . str_replace('/', DS, $src));
$image->resize((int) $width, null, 'W');
if (JFolder::create(JPATH_ROOT . DS . $dest . DS . $width) and $image->save(JPATH_ROOT . DS . $dest . DS . $width . DS . basename($src), 90)) {
    if (isset($_REQUEST['return']) and $_REQUEST['return'] == 'uri') {
        // Get link to optimized image
        $link = str_replace('/plugins/system/jsnmobilize/libraries/joomlashine/response/image/', '', JURI::root()) . str_replace(str_replace(array('/', '\\'), array('/', '/'), JPATH_ROOT), '', str_replace(array('/', '\\'), array('/', '/'), JPATH_ROOT . DS . $dest . DS . $width . DS . basename($src)));
        jexit($link);
    } else {
        // Send the requisite header information
        header('Content-Type: ' . $image->getMimeType());
        header('Content-Length: ' . filesize(JPATH_ROOT . DS . $dest . DS . $width . DS . basename($src)));
        // Read image content then send back to the client broswer
        if ($image = JFile::read(JPATH_ROOT . DS . $dest . DS . $width . DS . basename($src))) {
            jexit($image);
        } else {
            jexit(JText::_('JSN_MOBILIZE_READ_IMAGE_FAIL'));
        }
    }
} else {
    jexit(JText::_('JSN_MOBILIZE_RESIZE_IMAGE_FAIL'));
}