Ejemplo n.º 1
0
function HandlePreviewThumb(&$v, &$format, &$annotation)
{
    global $L, $C, $domain;
    list($width, $height) = explode('x', $format['preview_size']);
    $imagefile = "{$GLOBALS['BASE_DIR']}/cache/" . md5(uniqid(rand(), true)) . ".jpg";
    $i = GetImager();
    switch ($_REQUEST['preview']) {
        // Automatically crop and resize
        case 'automatic':
            $referrer_url = $_REQUEST['scan']['end_url'];
            $preview_url = $_REQUEST['scan']['preview'];
            if (!IsEmptyString($preview_url)) {
                $http = new Http();
                if ($http->Get($preview_url, TRUE, $referrer_url)) {
                    FileWrite($imagefile, $http->body);
                    $i->ResizeAuto($imagefile, $format['preview_size'], $annotation, $C['landscape_bias'], $C['portrait_bias']);
                } else {
                    $v->SetError(sprintf($L['PREVIEW_DOWNLOAD_FAILED'], $http->errstr));
                }
            } else {
                $v->SetError($L['NO_THUMBS_FOR_PREVIEW']);
            }
            break;
            // Handle uploaded image
        // Handle uploaded image
        case 'upload':
            if (is_uploaded_file($_FILES['upload']['tmp_name'])) {
                move_uploaded_file($_FILES['upload']['tmp_name'], $imagefile);
                @chmod($imagefile, 0666);
                $image = @getimagesize($imagefile);
                if ($image !== FALSE && $image[2] == IMAGETYPE_JPEG) {
                    // Image is properly sized
                    if ($image[0] == $width && $image[1] == $height) {
                        if ($C['have_imager']) {
                            $i->Annotate($imagefile, $annotation);
                        }
                    } else {
                        if ($C['have_imager'] && $C['handle_bad_size'] == 'crop') {
                            $i->ResizeAuto($imagefile, $format['preview_size'], $annotation, $C['landscape_bias'], $C['portrait_bias']);
                        } else {
                            @unlink($imagefile);
                            $v->SetError(sprintf($L['INVALID_IMAGE_SIZE'], $width, $height));
                        }
                    }
                } else {
                    @unlink($imagefile);
                    $v->SetError($L['INVALID_IMAGE']);
                }
            } else {
                $v->SetError($L['INVALID_UPLOAD']);
            }
            break;
            // Cropping an image
        // Cropping an image
        case 'crop':
            if (IsEmptyString($_REQUEST['scan']['preview'])) {
                $v->SetError($L['NO_THUMBS_FOR_PREVIEW']);
            }
            $imagefile = null;
            break;
            // Cropping or no image provided
        // Cropping or no image provided
        default:
            $imagefile = null;
            break;
    }
    return $imagefile;
}
Ejemplo n.º 2
0
define('TGPX', TRUE);
$path = realpath(dirname(__FILE__));
chdir($path);
// Make sure CLI API is being used
if (php_sapi_name() != 'cli') {
    echo "Invalid access: This script requires the CLI version of PHP\n";
    exit;
}
require_once '../includes/common.php';
require_once "{$GLOBALS['BASE_DIR']}/includes/mysql.class.php";
require_once "{$GLOBALS['BASE_DIR']}/includes/http.class.php";
require_once "{$GLOBALS['BASE_DIR']}/includes/template.class.php";
require_once "{$GLOBALS['BASE_DIR']}/includes/imager.class.php";
require_once "{$GLOBALS['BASE_DIR']}/admin/includes/functions.php";
// Get imager object for preview cropping/resizing
$imager = GetImager();
// Get the configuration ID from command line parameter
$config_id = $GLOBALS['argv'][1];
// Define penalties
$penalties = array('ignore' => 0x0, 'report' => 0x1, 'disable' => 0x2, 'delete' => 0x4, 'blacklist' => 0x8);
// Exception bitmasks
$exceptions = array('connect' => 0x1, 'forward' => 0x2, 'broken' => 0x4, 'blacklist' => 0x8, 'norecip' => 0x10, 'no2257' => 0x20, 'excessivelinks' => 0x40, 'thumbchange' => 0x80, 'pagechange' => 0x100, 'content_server' => 0x200, 'badformat' => 0x400);
$DB = new DB($C['db_hostname'], $C['db_username'], $C['db_password'], $C['db_name']);
$DB->Connect();
// Get scanner configuration information
$config = $DB->Row('SELECT * FROM `tx_scanner_configs` WHERE `config_id`=?', array($config_id));
if (!$config) {
    echo "Invalid configuration ID {$config_id}\n";
    exit;
}
$configuration = unserialize($config['configuration']);
Ejemplo n.º 3
0
function txPreviewFilter()
{
    global $DB, $json, $C;
    VerifyPrivileges(P_GALLERY_MODIFY, TRUE);
    require_once "{$GLOBALS['BASE_DIR']}/includes/imager.class.php";
    $out = array('status' => JSON_SUCCESS, 'message' => '', 'close' => 0, 'level' => 0);
    $image = SafeFilename("{$C['preview_dir']}/{$_REQUEST['preview_id']}.jpg", FALSE);
    $i = GetImager();
    if (is_file($image)) {
        $out['image'] = "{$C['preview_url']}/{$_REQUEST['preview_id']}.jpg?" . rand();
        // See if the starting image is in the database, and if not add it
        if ($DB->Count("SELECT COUNT(*) FROM `tx_undos` WHERE `preview_id`=? AND `undo_level`=0", array($_REQUEST['preview_id'])) < 1) {
            $DB->Update("INSERT INTO `tx_undos` VALUES (?, 0, ?)", array($_REQUEST['preview_id'], file_get_contents($image)));
        }
        switch ($_REQUEST['filter']) {
            case 'reset':
                $undo = $DB->Row("SELECT * FROM `tx_undos` WHERE `preview_id`=? AND `undo_level`=0", array($_REQUEST['preview_id']));
                $DB->Update("DELETE FROM `tx_undos` WHERE `preview_id`=? AND `undo_level` > 0", array($_REQUEST['preview_id']));
                FileWrite($image, $undo['image']);
                break;
            case 'undo':
                $level = $DB->Count("SELECT MAX(`undo_level`) FROM `tx_undos` WHERE `preview_id`=?", array($_REQUEST['preview_id']));
                $undo = $DB->Row("SELECT * FROM `tx_undos` WHERE `preview_id`=? AND `undo_level`=?", array($_REQUEST['preview_id'], --$level));
                $DB->Update("DELETE FROM `tx_undos` WHERE `preview_id`=? AND `undo_level`=?", array($_REQUEST['preview_id'], $level + 1));
                FileWrite($image, $undo['image']);
                $out['level'] = $level;
                break;
            case 'save':
                $i->ApplyFilter($image, 'compress', null);
                $DB->Update("DELETE FROM `tx_undos` WHERE `preview_id`=?", array($_REQUEST['preview_id']));
                $out['close'] = 1;
                break;
            case 'cancel':
                $out['close'] = 1;
                $undo = $DB->Row("SELECT * FROM `tx_undos` WHERE `preview_id`=? AND `undo_level`=0", array($_REQUEST['preview_id']));
                $DB->Update("DELETE FROM `tx_undos` WHERE `preview_id`=?", array($_REQUEST['preview_id']));
                if ($undo) {
                    FileWrite($image, $undo['image']);
                }
                break;
            default:
                $fd = fopen("{$GLOBALS['BASE_DIR']}/data/_filter_lock", 'w');
                flock($fd, LOCK_EX);
                $i->ApplyFilter($image, $_REQUEST['filter'], $_REQUEST['input']);
                $level = $DB->Count("SELECT MAX(`undo_level`) FROM `tx_undos` WHERE `preview_id`=?", array($_REQUEST['preview_id']));
                $DB->Update("INSERT INTO `tx_undos` VALUES (?, ?, ?)", array($_REQUEST['preview_id'], ++$level, file_get_contents($image)));
                flock($fd, LOCK_UN);
                fclose($fd);
                $out['level'] = $level;
                break;
        }
    } else {
        $out['close'] = 1;
        $out['status'] = JSON_FAILURE;
        $out['message'] = 'This thumbnail cannot be modified because it is located on a remote server';
    }
    echo $json->encode($out);
}
Ejemplo n.º 4
0
function txCropWithBias()
{
    global $DB, $C;
    require_once "{$GLOBALS['BASE_DIR']}/includes/imager.class.php";
    $gallery = $DB->Row('SELECT * FROM `tx_galleries` WHERE `gallery_id`=?', array($_REQUEST['gallery_id']));
    $categories =& CategoriesFromTags($gallery['categories']);
    $format = GetCategoryFormat($gallery['format'], $categories[0]);
    $annotation =& LoadAnnotation($format['annotation'], $categories[0]['name']);
    $tempfile = md5(uniqid(rand(), true)) . ".jpg";
    $http = new Http();
    if ($http->Get($_REQUEST['imagefile'], TRUE, $gallery['gallery_url'])) {
        FileWrite("{$GLOBALS['BASE_DIR']}/cache/{$tempfile}", $http->body);
        $i = GetImager();
        $i->ResizeAuto("{$GLOBALS['BASE_DIR']}/cache/{$tempfile}", $_REQUEST['dimensions'], $annotation, $_REQUEST['bias_land'], $_REQUEST['bias_port']);
        $preview = AddPreview($gallery['gallery_id'], $_REQUEST['dimensions'], "{$GLOBALS['BASE_DIR']}/cache/{$tempfile}");
        UpdateThumbSizes($_REQUEST['dimensions']);
        include_once 'includes/crop-complete.php';
    } else {
        $error = 'Could not download image file: ' . $http->errstr;
        include_once 'includes/error.php';
    }
}