<?php
//////////////////////////////////////////////////////////////////////
//
// $Id: image.php,v 1.7 2002/02/04 18:15:10 carney Exp $
//
// Copyright (C) 2002 Michael Carney
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
//////////////////////////////////////////////////////////////////////
function image_submit_handler(&$vars, &$errors)
// This will get called by submitForm
{
global $auto_form_mode,$p;
$from = $vars["file"];
$align = $vars["align"];
$id = $vars["id"];
if ($from != "none")
// means we need to load a new image
{
$info = GetImageSize($from);
if (isset($info) == false)
{
$errors["file"] = "badImageFile";
return;
}
if (($info[1] > $p->getSitePref("image_height"))
|| ($info[0] > $p->getSitePref("image_width")))
// The image is too big, so we need to scale it down before
// uploading it into the database.
{
$geometry = $p->getSitePref("image_width")."x".$p->getSitePref("image_height");
$mogrify = $p->getSitePref("mogrify_path");
$result = passthru("$mogrify -geometry $geometry $from");
$info = GetImageSize("$from");
}
$vars["height"] = $info[1];
$vars["width"] = $info[0];
$vars["heightwidth"] = $info[3];
switch($info[2])
{
case 1:
{
$vars["content_type"] = "image/gif";
}
break;
case 2:
{
$vars["content_type"] = "image/jpeg";
}
break;
case 3:
{
$vars["content_type"] = "image/png";
}
break;
}
$fp = fopen($from, "r");
if ($fp)
{
global $p;
$vars["data"] = addslashes(fread($fp, filesize($from)));
fclose ($fp);
$def_width = $p->getSitePref("thumb_width");
$def_height = $p->getSitePref("thumb_width");
$geometry = $def_width."x".$def_height;
$mogrify = $p->getSitePref("mogrify_path");
$result = passthru("$mogrify -format png -geometry $geometry $from");
$thumb_info = GetImageSize("$from.png");
$vars["thumb_width"] = $thumb_info[0];
$vars["thumb_height"] = $thumb_info[1];
$fp = fopen ("$from.png","r");
if ($fp)
{
$vars["thumbnail"] = addslashes(fread($fp, filesize("$from.png")));
}
}
else
$errors["file"] = "badImageUpload" ;
}
return 0;
}
function image_post_submit_handler(&$vars, $id)
{
}
function image_display_handler($id)
{
global $p;
include_once ("util/misc.php");
include_once ("util/manila.php");
$result = db_query("select * from image where image.id='$id'");
$vars = mysql_fetch_assoc($result);
$vars["image_url"] = "image.php?id=$id";
return $vars;
}
?>