steffen: server/kolab-horde-fbview/kolab-horde-fbview/fbview/services/images colorpicker.php, NONE, 1.1 pixel.php, NONE, 1.1 view.php, NONE, 1.1

cvs at intevation.de cvs at intevation.de
Mon Oct 31 12:43:35 CET 2005


Author: steffen

Update of /kolabrepository/server/kolab-horde-fbview/kolab-horde-fbview/fbview/services/images
In directory doto:/tmp/cvs-serv18388/kolab-horde-fbview/kolab-horde-fbview/fbview/services/images

Added Files:
	colorpicker.php pixel.php view.php 
Log Message:
Fbview in separate package

--- NEW FILE: colorpicker.php ---
<?php
/*
 * $Horde: horde/services/images/colorpicker.php,v 1.14 2004/01/01 16:17:37 jan Exp $
 *
 * Copyright 2002-2004 Michael Cochrane <mike at graftonhall.co.nz>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

@define('HORDE_BASE', dirname(__FILE__) . '/../..');
require_once HORDE_BASE . '/lib/base.php';

$title = _("Color Picker");
require HORDE_TEMPLATES . '/common-header.inc';

$form = Util::getFormData('form');
$target = Util::getFormData('target');

echo Horde::img('colorpicker.png', '', 'id="colorpicker" onclick="changeColor(getColor(event)); return false;" onmousemove="demoColor(getColor(event)); return false;" style="cursor:crosshair;background-color:white;padding:1px"'); 
?>

<div id="colorDemo" style="background-color:white;width:100px;height:20px;padding:1px"></div>
<script language="Javascript" type="text/javascript">
<!--
function changeColor(color)
{
    if (parent.opener.closed) {
        alert("<?php echo addslashes(_("The Options window has closed. Exiting.")) ?>");
        this.close();
        return;
    }

    if (!parent.opener.document.<?php echo $form ?>) {
        alert("<?php echo addslashes(_("This window must be called from an Options window")) ?>");
        this.close();
        return;
    }
    
    parent.opener.document.<?php echo $form ?>["<?php echo $target ?>"].value = color;
    parent.opener.document.<?php echo $form ?>["<?php echo $target ?>"].style.backgroundColor = color;

    this.close();
}

function demoColor(color)
{
    var target = document.getElementById("colorDemo");
    target.style.backgroundColor = color;
}

function getColor(event) {
    var img = document.getElementById("colorpicker");

    var x = event.clientX - 10;
    var y = event.clientY - 10;
    
    var rmax = 0;
    var gmax = 0;
    var bmax = 0;
    
    if (y <= 32) {
        rmax = 255;
        gmax = (y / 32.0) * 255;
        bmax = 0;
    } else if (y <= 64) {
        y = y - 32;
        rmax = 255 - (y / 32.0) * 255;
        gmax = 255;
        bmax = 0;
    } else if (y <= 96) {
        y = y - 64;
        rmax = 0;
        gmax = 255;
        bmax = (y / 32.0) * 255;
    } else if (y <= 128) {
        y = y - 96;
        rmax = 0;
        gmax = 255 - (y / 32.0) * 255;
        bmax = 255;
    } else if (y <= 160) {
        y = y - 128;
        rmax = (y / 32.0) * 255;
        gmax = 0;
        bmax = 255;
    } else {
        y = y - 160;
        rmax = 255;
        gmax = 0;
        bmax = 255 - (y / 32.0) * 255;
    }

    if (x <= 50) {
        var r = Math.floor(rmax * x / 50.0);
        var g = Math.floor(gmax * x / 50.0);
        var b = Math.floor(bmax * x / 50.0);
        
        return makeColor(r,g,b);
    } else {
        x = x - 50;
        var r = Math.floor(rmax + (x / 50.0) * (255 - rmax));    
        var g = Math.floor(gmax + (x / 50.0) * (255 - gmax));    
        var b = Math.floor(bmax + (x / 50.0) * (255 - bmax));   
        return makeColor(r,g,b);
    }
}

function makeColor(r, g, b)
{
    color = "#";
    color += hex(Math.floor(r / 16));
    color += hex(r % 16);
    color += hex(Math.floor(g / 16));
    color += hex(g % 16);
    color += hex(Math.floor(b / 16));
    color += hex(b % 16);
    return color;
}

function hex(Dec)
{   
    if (Dec == 10) return "A";
    if (Dec == 11) return "B";
    if (Dec == 12) return "C";
    if (Dec == 13) return "D";
    if (Dec == 14) return "E";
    if (Dec == 15) return "F";
    return "" + Dec;
}
//-->
</script>
</body>
</html>


--- NEW FILE: pixel.php ---
<?php
/**
 * $Horde: horde/services/images/pixel.php,v 1.14 2004/05/06 21:41:39 chuck Exp $
 *
 * Copyright 2002-2004 Chuck Hagenbuch <chuck at horde.org>
 *
 * See the enclosed file COPYING for license information (LGPL).  If you
 * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 */

@define('HORDE_BASE', dirname(__FILE__) . '/../..');
require_once HORDE_BASE . '/lib/core.php';

header('Content-type: image/gif');
header('Expires: Wed, 21 Aug 1969 11:11:11 GMT');
header('Cache-Control: no-cache');
header('Cache-Control: must-revalidate');

$rgb = str_replace('#', '', Util::getFormData('c'));

$r = hexdec(substr($rgb, 0, 2));
$g = hexdec(substr($rgb, 2, 2));
$b = hexdec(substr($rgb, 4, 2));

if ($rgb) {
    printf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c',
           71,73,70,56,57,97,1,0,1,0,128,0,0,$r,$g,$b,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
} else {
    printf('%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%',
           71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
}

--- NEW FILE: view.php ---
<?php
/**
 * Displays an image and allows modifications if required.
 *
 * Copyright 2003-2004 Marko Djukic <marko at oblo.com>
 *
 * See the enclosed file COPYING for license information (LGPL). If you did not
 * receive this file, see http://www.fsf.org/copyleft/lgpl.html.
 *
 * $Horde: horde/services/images/view.php,v 1.20 2004/04/16 17:06:20 jan Exp $
 *
 * @author Marko Djukic <marko at oblo.com>
 * @version $Revision: 1.1 $
 */

@define('HORDE_BASE', dirname(__FILE__) . '/../..');
require_once HORDE_BASE . '/lib/base.php';

/* Get file info. The following parameters are available:
 *  'f' - the filename.
 *  's' - the source, either the 'tmp' directory or VFS.
 *  'c' - which app's config to use for VFS, defaults to Horde.
 *  'n' - the name to set to the filename or default to same as filename.
 *  'a' - perform some action on the image, such as scaling. */
$file = basename(Util::getFormData('f'));
$source = strtolower(Util::getFormData('s', 'tmp'));
$app_conf = strtolower(Util::getFormData('c', 'horde'));
$name = Util::getFormData('n', $file);
$action = strtolower(Util::getFormData('a'));

switch ($source) {
case 'vfs':
    /* Change app if needed to get the right VFS config. */
    $changed_conf = $registry->pushApp($app_conf);

    /* Getting a file from Horde's VFS. */
    require_once 'VFS.php';
    $vfs = &VFS::singleton($conf['vfs']['type'], Horde::getDriverConfig('vfs', $conf['vfs']['type']));
    $path = Util::getFormData('p');
    $file_data = $vfs->read($path, $file);
    if (is_a($file_data, 'PEAR_Error')) {
        Horde::logMessage(sprintf('Error displaying image [%s]: %s', $path . '/' . $file, $file_data->getMessage()), __FILE__, __LINE__, PEAR_LOG_ERR);
        exit;
    }

    /* Return the original app if changed previously. */
    if ($changed_conf) {
        $registry->popApp($app_conf);
    }
    break;

case 'tmp':
    /* Getting a file from Horde's temp dir. */
    $tmpdir = Horde::getTempDir();
    if (empty($action) || $action == 'resize') {
        /* Use original if no action or if resizing. */
        $file_name = $tmpdir . '/' . $file;
    } else {
        $file_name = $tmpdir . '/mod_' . $file;
        if (!file_exists($file_name)) {
            copy($tmpdir . '/' . $file, $file_name);
        }
    }
    if (!file_exists($file_name)) {
        Horde::logMessage(sprintf('Image not found [%s]', $file_name), __FILE__, __LINE__, PEAR_LOG_ERR);
        exit;
    }
    $size = filesize($file_name);
    $fp = @fopen($file_name, 'r');
    $file_data = fread($fp, $size);
    fclose($fp);
    break;
}

/* Load the image object. */
require_once 'Horde/Image.php';
$params = array('temp' => Horde::getTempDir());
if (!empty($conf['image']['convert'])) {
    $image = &Horde_Image::singleton('im', $params);
} else {
    $image = &Horde_Image::singleton('gd', $params);
}
$image->loadString($file, $file_data);

/* Check if no editing action required and send the image to browser. */
if (empty($action)) {
    $image->display();
    exit;
}

/* Image editing required. */
switch ($action) {
case 'rotate':
    $image->rotate(Util::getFormData('v'));
    break;

case 'flip':
    $image->flip();
    break;

case 'mirror':
    $image->mirror();
    break;

case 'grayscale':
    $image->grayscale();
    break;

case 'resize':
    list($width, $height, $ratio) = explode('.', Util::getFormData('v'));

    /* If no width or height has been passed, get the original
     * ones. */
    if (empty($width) || empty($height)) {
        $orig = $image->getDimensions();
    }
    if (empty($width)) {
        $width = $orig['width'];
    }
    if (empty($height)) {
        $height = $orig['height'];
    }

    $image->resize($width, $height, $ratio);

    /* Since the original is always used for resizing make sure the
     * write is to 'mod_'. */
    $file_name = $tmpdir . '/mod_' . $file;
    break;
}

/* Write out any changes to the temporary file. */
$fp = @fopen($file_name, 'wb');
fwrite($fp, $image->raw());
fclose($fp);

$image->display();





More information about the commits mailing list