Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactor annotate photo, watermark photo, image.php

Rewritten the annotate photo function to no longer use a temporary file.
Computers nowadays are fast enough to generate the image on the fly.

Moved annotate photo into a subclass annotatePhoto and made a similar
change to watermarking, creating subclass watermarkPhoto. Moved parts
of image.php into these classes and also into the class photo.
  • Loading branch information...
commit 3f4ab554dafa1af1a2789fb6e416e2108c71dd57 1 parent 9e45426
@jeroenrnl authored
View
8 php/auth.inc.php
@@ -68,10 +68,6 @@
// no user was in the session, try logging in
if ($_action == "logout") {
- // delete left over temp files
- if($user) {
- delete_temp_annotated_files($user->get("user_id"));
- }
session_destroy();
$user = null;
redirect("logon.php", "Logout");
@@ -100,10 +96,6 @@
$updated_user->set("lastlogin", "now()");
$updated_user->set("lastip", $_SERVER["REMOTE_ADDR"]);
$updated_user->update();
-
- // delete left over temp files
- delete_temp_annotated_files($user->get("user_id"));
-
} else {
$this_page=urlencode(preg_replace("/^\//", "", $_SERVER['REQUEST_URI']));
redirect("logon.php?redirect=" . $this_page);
View
210 php/classes/annotatedPhoto.inc.php
@@ -0,0 +1,210 @@
+<?php
+/**
+ * A class representing an annotated photo
+ * An annotated photo is a photo with information about the
+ * photo added to the image
+ *
+ * This file is part of Zoph.
+ *
+ * Zoph is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Zoph 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with Zoph; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * @package Zoph
+ * @author Jeroen Roos
+ * @author Richard P. Childs
+ */
+
+class annotatedPhoto extends photo {
+
+ /** The vars that are going to be displayed on the photo */
+ private $vars=array();
+
+ /**
+ * Creates a jpeg photo with
+ * text annotation at the bottom.
+ *
+ * Copyright 2003, Nixon P. Childs
+ * @param string type of image to display mid, thumb or null for full-sized
+ * @return array Return an array that contains:
+ * array headers: the headers
+ * string jpeg: the jpeg file
+ * @throws photoException
+ */
+ public function display($type=null) {
+ if($type=="full") {
+ $type=null;
+ }
+ $headers=array();
+ $vars=&$this->vars;
+ if ($type == 'mid') {
+ $font = 4;
+ $padding = 2;
+ $indent = 8;
+ } else if (empty($type)) {
+ $font = 5;
+ $padding = 2;
+ $indent = 8;
+ } else {
+ throw new photoException("Unknown type");
+ }
+
+ /* ********************************
+ * Read in original image.
+ * Need to do now so we know
+ * the width of the text lines.
+ * ********************************/
+
+ $image_path = conf::get("path.images") . $this->get("path");
+ $name=$this->get("name");
+ if (empty($type)) {
+ $image_path .= "/" . $name;
+ } else {
+ $image_path .= "/" . $type . "/" . $type . "_" . $name;
+ }
+
+ $image_info = getimagesize($image_path);
+ switch ($image_info[2]) {
+ case 1:
+ $orig_image = imagecreatefromgif($image_path);
+ break;
+ case 2:
+ $orig_image = imagecreatefromjpeg($image_path);
+ break;
+ case 3:
+ $orig_image = imagecreatefrompng($image_path);
+ break;
+ default:
+ log::msg("Unsupported image type.", log::ERROR, log::IMG);
+ return '';
+ }
+
+ $row = ImageSY($orig_image) + ($padding/2);
+ $maxWidthPixels = ImageSX($orig_image) - (2 * $indent);
+ $maxWidthChars = floor($maxWidthPixels / ImageFontWidth($font)) - 1;
+
+
+ /* **********************************************
+ * Create Image
+ * In order to create the text area, we must
+ * first create the text and determine how much
+ * space it requires.
+ *
+ * I tried implode;wordwrap;explode, but
+ * wordwrap doesn't respect \n's in the text.
+ * To complicate things, ImageString just
+ * renders \n as an upside-down Y.
+ *
+ * So the current solution is a little awkward,
+ * but it works. The only (known) problem is
+ * that wrapped lines don't have the same
+ * right margin as non-wrapped lines. This is
+ * because wordwrap doesn't take into account
+ * the line separation string.
+ * **********************************************/
+
+ $count = 0;
+ $final_array=array();
+ if ($vars) {
+ while (list($key, $val) = each($vars)) {
+ $tmp_array = explode("\n", wordwrap($val, $maxWidthChars, "\n "));
+ while (list($key1, $val1) = each($tmp_array)) {
+ $final_array[$count++] = $val1;
+ }
+ }
+ }
+
+ $noted_image = ImageCreateTrueColor (ImageSX($orig_image), ImageSY($orig_image) + ((ImageFontHeight($font) + $padding) * $count));
+ $white = ImageColorAllocate($noted_image, 255,255, 255);
+
+ /* Use a light grey background to hide the jpeg artifacts caused by the sharp edges in text. */
+
+ $offwhite = ImageColorAllocate($noted_image, 240,240, 240);
+ ImageFill($noted_image, 0, ImageSY($orig_image) +1, $offwhite);
+ $black = ImageColorAllocate($noted_image, 0, 0, 0);
+ ImageColorTransparent($noted_image, $black);
+
+ ImageCopy($noted_image, $orig_image, 0, 0, 0, 0, ImageSX($orig_image), ImageSY($orig_image));
+
+ if ($final_array) {
+ while (list($key, $val) = each($final_array)) {
+ ImageString ($noted_image, $font, $indent, $row, $val, $black);
+ $row += ImageFontHeight($font) + $padding;
+ }
+ }
+
+ ob_start();
+ imagejpeg($noted_image);
+ imagedestroy($orig_image);
+ imagedestroy($noted_image);
+ $jpeg=ob_get_clean();
+
+ $headers["Content-Length"]=strlen($jpeg);
+ $headers["Content-Disposition"]="inline; filename=" . $name;
+ // Return current time as last modified time
+ // this is debatable, we could also send the file time as last modified
+ $headers["Last-Modified"]=gmdate("D, d M Y H:i:s") . ' GMT';
+ $headers["Content-type"]="image/jpeg";
+
+ return array($headers, $jpeg);
+
+
+ }
+
+ /**
+ * Sets fields from the given array. Can be used to set vars
+ * directly from a GET or POST.
+ * @param array vars to import into $this->vars;
+ */
+ public function setVars(array $vars) {
+ reset($vars);
+ while (list($key, $val) = each($vars)) {
+
+ // ignore empty keys or values
+ if (empty($key) || $val == "") { continue; }
+
+ if (strcmp(Substr($key, strlen($key) - 3), "_cb") == 0) {
+
+ /* *****************************************
+ * Everthing else uses the checkbox name
+ * as the "get" key.
+ * *****************************************/
+
+ $real_key = Substr($key, 0, strlen($key) - 3);
+ $real_val = $vars[$real_key];
+
+ /* *****************************************
+ * Have to handle title separately because
+ * breadcrumbs.inc.php assumes title is
+ * the page title.
+ * *****************************************/
+
+ if ($real_key == "photo_title") {
+ $real_key = "title";
+ }
+ else if ($real_key == "extra") {
+ $real_key = $vars["extra_name"];
+ }
+
+ $this->vars[$real_key] = translate($real_key, 0) . ": " . $real_val;
+ }
+ }
+ }
+
+ /**
+ * Return the vars, so the can be re-used after a form POST
+ */
+ public function getVars() {
+ return $this->vars;
+ }
+}
+?>
View
112 php/classes/watermarkedPhoto.inc.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * A class representing a watermarked photo
+ * This is a photo with a "watermark" superimposed over it
+ * usually to prevent unauthorized use the photo
+ *
+ * This file is part of Zoph.
+ *
+ * Zoph is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Zoph 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with Zoph; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * @package Zoph
+ * @author Jeroen Roos
+ */
+
+class watermarkedPhoto extends photo {
+ /**
+ * Display the watermarked image
+ * @param string type of image to display mid, thumb or null for full-sized
+ * @return array Return an array that contains:
+ * array headers: the headers
+ * string jpeg: the jpeg file
+ * @todo only supports JPEG currently, should support more filetypes
+ */
+ public function display($type=null) {
+ $headers=array();
+ // Only fullsize images are (currently) watermarked
+ if(empty($type)) {
+ $watermark_file = conf::get("path.images") . "/" . conf::get("watermark.file");
+ if (file_exists($watermark_file)) {
+ $name = $this->get("name");
+ $image_path = conf::get("path.images") . "/" . $this->get("path") . "/" . $name;
+ $image=imagecreatefromjpeg($image_path);
+ $image=$this->watermark($image, $watermark_file, conf::get("watermark.pos.x"), conf::get("watermark.pos.y"), conf::get("watermark.transparency"));
+ ob_start();
+ imagejpeg($image);
+ imagedestroy($image);
+ $jpeg=ob_get_clean();
+ $headers["Content-Length"]=strlen($jpeg);
+ $headers["Content-Disposition"]="inline; filename=" . $name;
+ // Return current time as last modified time
+ // this is debatable, we could also send the file time as last modified
+ $headers["Last-Modified"]=gmdate("D, d M Y H:i:s") . ' GMT';
+ $headers["Content-type"]="image/jpeg";
+
+ return array($headers, $jpeg);
+
+ }
+ }
+ return parent::display($type);
+ }
+
+ /**
+ * Watermark the photo
+ * @param imageresource photo
+ * @param string GIF image to be used as watermark
+ * @param string position horizontally (center, left or right)
+ * @param string position vertically (center, top or bottom)
+ * @param int transparency (0 = invisible, 100 = no transparency)
+ * @return imageresource watermarked photo
+ */
+ private function watermark($orig, $watermark, $positionX = "center", $positionY = "center", $transparency = 50) {
+
+ $wm=imagecreatefromgif($watermark);
+
+ $width_orig=ImageSX($orig);
+ $height_orig=ImageSY($orig);
+
+ $width_wm=ImageSX($wm);
+ $height_wm=ImageSY($wm);
+
+ switch ($positionX) {
+ case "left":
+ $destX = 5;
+ break;
+ case "right":
+ $destX = $width_orig - $width_wm - 5;
+ break;
+ default:
+ $destX = ($width_orig / 2) - ($width_wm / 2);
+ break;
+ }
+
+ switch ($positionY) {
+ case "top":
+ $destY = 5;
+ break;
+ case "bottom":
+ $destY = $height_orig - $height_wm - 5;
+ break;
+ default:
+ $destY = ($height_orig / 2) - ($height_wm / 2);
+ break;
+ }
+ ImageCopyMerge($orig, $wm, $destX, $destY, 0, 0, $width_wm, $height_wm, $transparency);
+ imagedestroy($wm);
+ return $orig;
+ }
+
+
+}
+?>
View
71 php/htmlMimeMail.php
@@ -136,23 +136,15 @@ public function setHTMLBody($data, $isfile = false) {
}
/**
- * Adds an image to the list of embedded images.
+ * Adds an image to the list of embedded images. The source is a string containing the image.
*
- * @param string The image file name OR image data itself
- * @param string The content type
- * @param string The filename of the image. Only use if $file is the image data
- * @param bool Whether $file is a filename or not. Defaults to true
+ * @paramstring The image data.
+ * @param string The file name
+ * @param string The content type
* @return bool true
*/
- public function addHTMLImage($file, $c_type='application/octet-stream',
- $name = '', $isfilename = true) {
- $filedata = ($isfilename === true) ? $this->file2str($file)
- : $file;
- if ($isfilename === true) {
- $filename = ($name == '' ? basename($file) : basename($name));
- } else {
- $filename = basename($name);
- }
+ public function addHTMLImageFromString($filedata, $filename, $c_type='application/octet-stream') {
+ $filename = basename($filename);
$this->html_images[] = array(
'body' => $filedata,
'name' => $filename,
@@ -163,45 +155,58 @@ public function addHTMLImage($file, $c_type='application/octet-stream',
}
/**
- * Adds a file to the list of attachments.
+ * Adds an image to the list of embedded images. The source is a file on disk.
*
- * @param string The file name of the file to attach OR the file data itself
- * @param string The content type
- * @param string The filename of the attachment. Only use if $file is the file data
- * @param bool Whether $file is a filename or not. Defaults to true
- * @return bool true
+ * @param string The file to be used as attachment
+ * @param string The content type
+ * @param string encoding.
+ */
+ public function addHTMLImageFromFile($file, $c_type='application/octet-stream') {
+ $filedata = $this->file2str($file);
+ return $this->addHTMLImageFromString($filedata, $file, $c_type);
+ }
+
+ /**
+ * Adds a file to the list of attachments. The source is a string containing the contents of the file.
+ *
+ * @param string The file data to use as attachment
+ * @param string The content type
+ * @param string The filename of the attachment.
+ * @param string encoding.
* @throws MailException
*/
- public function addAttachment($file, $c_type = 'application/octet-stream',
- $name = '', $isfilename = true,
- $encoding = 'base64') {
- $filedata = ($isfilename === true) ? $this->file2str($file)
- : $file;
- if ($isfilename === true) {
- // Force the name the user supplied, otherwise use $file
- $filename = (!empty($name)) ? $name : $file;
- } else {
- $filename = $name;
- }
+ public function addAttachmentFromString($filedata, $filename, $c_type = 'application/octet-stream', $encoding = 'base64') {
if (empty($filename)) {
throw new MailException("The supplied filename for the attachment can\'t be empty");
}
$filename = basename($filename);
-
$this->parts[] = array(
'body' => $filedata,
'name' => $filename,
'c_type' => $c_type,
'encoding' => $encoding
);
- return true;
}
/**
+ * Adds a file to the list of attachments. The source is a file on disk.
+ *
+ * @param string The file to be used as attachment
+ * @param string The content type
+ * @param string encoding.
+ */
+ public function addAttachmentFromFile($file, $c_type = 'application/octet-stream', $encoding = 'base64') {
+ $filedata=$this->file2str($file);
+ $this->addAttachmentFromString($filedata, $file, $c_type, $encoding);
+ }
+
+
+ /**
* Get the contents of the given file name as string
*
* @param string path of file to process
* @return string contents of $file_name
+ * @throws mailException
*/
private function file2str($file_name) {
if (!is_readable($file_name)) {
View
84 php/image.php
@@ -1,5 +1,5 @@
<?php
-/*
+/**
* This file is part of Zoph.
*
* Zoph is free software; you can redistribute it and/or modify
@@ -14,10 +14,16 @@
* You should have received a copy of the GNU General Public License
* along with Zoph; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * @package Zoph
+ * @author Jason Geiger
+ * @author Jeroen Roos
+ * @author Alan Shutko
*/
session_cache_limiter("public");
require_once("variables.inc.php");
$hash = getvar("hash");
+ $annotated = getvar('annotated');
define("IMAGE_PHP", 1);
require_once("include.inc.php");
@@ -54,6 +60,13 @@
die($e->getMessage());
}
}
+ } else if (ANNOTATE_PHOTOS && $annotated) {
+ $photo = new annotatedPhoto($photo_id);
+ $found = $photo->lookupForUser($user);
+ $photo->setVars($request_vars);
+ if(getvar("_size")=="mid") {
+ $type=MID_PREFIX;
+ }
} else if ($type==MID_PREFIX || $type==THUMB_PREFIX || empty($type)) {
$photo = new photo($photo_id);
$found = $photo->lookupForUser($user);
@@ -62,62 +75,27 @@
}
if ($found) {
$name = $photo->get("name");
-
- $annotated = getvar('annotated');
- if (ANNOTATE_PHOTOS && $annotated) {
- $image_path = ANNOTATE_TEMP_DIR . "/" .
- $photo->get_annotated_file_name($user);
- } else {
- $watermark_file="";
- $image_path = conf::get("path.images") . "/" . $photo->get("path") . "/";
- if (!$user->is_admin()) {
- $permissions = $user->get_permissions_for_photo($photo_id);
- $watermark = $permissions->get("watermark_level");
- $photolevel=$photo->get("level");
- if(conf::get("watermark.enable") && ($photolevel > $watermark)) {
- $watermark_file = conf::get("path.images") . "/" . conf::get("watermark.file");
- if (!file_exists($watermark_file)) {
- $watermark_file="";
- }
- }
- }
-
- if (conf::get("watermark.enable") && $watermark_file && !$type) {
- $image_path .= $name;
- $image=imagecreatefromjpeg($image_path);
- watermark_image(&$image, $watermark_file, conf::get("watermark.pos.x"), conf::get("watermark.pos.y"), conf::get("watermark.transparency"));
- header("Content-type: image/jpeg");
- imagejpeg($image);
- imagedestroy($image);
- exit;
- } else {
- if ($type) {
- $image_path .= $type . "/" . $type . "_";
- }
- $image_path .= $name;
+ $image_path = conf::get("path.images") . "/" . $photo->get("path") . "/";
+ $watermark_file="";
+
+ if(!$user->is_admin() && conf::get("watermark.enable")) {
+ $permissions = $user->get_permissions_for_photo($photo_id);
+ $watermark = $permissions->get("watermark_level");
+ $photolevel=$photo->get("level");
+ if($photolevel > $watermark) {
+ $photo=new watermarkedPhoto($photo_id);
+ $photo->lookup();
}
+ } else {
}
- // the following thanks to Alan Shutko
- $mtime = filemtime($image_path);
- $filesize = filesize($image_path);
- $gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
- // we assume that the client generates proper RFC 822/1123 dates
- // (should work for all modern browsers and proxy caches)
- if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
- $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
- header("HTTP/1.1 304 Not Modified");
- exit;
+ list($headers, $image)=$photo->display($type);
+
+ foreach($headers as $label=>$value) {
+ header($label . ": " . $value);
}
- $image_type = get_image_type($image_path);
- if ($image_type) {
- header("Content-Length: " . $filesize);
- header("Content-Disposition: inline; filename=" . $name);
- header("Last-Modified: " . $gmt_mtime);
- header("Content-type: " . $image_type);
- readfile($image_path);
- exit;
- }
+ echo $image;
+ exit;
}
require_once("header.inc.php");
?>
View
53 php/mail.php
@@ -30,17 +30,26 @@
$message = getvar("message");
$includeurl = getvar("includeurl");
$annotate = getvar("annotate");
+ $annotate_vars = getvar("annotate_vars");
if (!ANNOTATE_PHOTOS) {
$annotate = 0;
}
- // image will have been deleted if sent
if ($annotate) {
$skipcrumb = true;
+ $photo=new annotatedPhoto($photo_id);
+ if(!empty($annotate_vars)) {
+ parse_str($annotate_vars, $vars);
+ } else {
+ $vars=$request_vars;
+ $annotate_vars=http_build_query($vars, "&amp;");
+ }
+ $photo->setVars($vars);
+ } else {
+ $photo = new photo($photo_id);
}
- $photo = new photo($photo_id);
$found = $photo->lookupForUser($user);
if (!$found) {
@@ -56,17 +65,16 @@
"X-Zoph-Version" => VERSION
);
$headers="";
+
$size = getvar("_size");
-
- if ($annotate) {
- $file = $photo->get_annotated_file_name($user);
- $dir = ANNOTATE_TEMP_DIR . "/";
- }
- else if ($size == "full") {
+
+ if($annotate) {
+ $file=$photo->get("name");
+ $size = $vars["_size"];
+ } else if ($size == "full") {
$file = $photo->get("name");
$dir = conf::get("path.images") . $photo->get("path") . "/";
- }
- else {
+ } else {
$file = MID_PREFIX . "_" . $photo->get("name");
$dir = conf::get("path.images") . $photo->get("path") . "/" .
MID_PREFIX . "/";
@@ -81,7 +89,12 @@
}
$html .= "</center>\n";
- $mail->addHTMLImage($dir . "/" . $file, get_image_type($file), $file);
+ if($annotate) {
+ list($headers,$image)=$photo->display($size);
+ $mail->addHTMLImageFromString($image, $photo->get("name"), $headers["Content-type"]);
+ } else {
+ $mail->addHTMLImageFromFile($dir . "/" . $file, get_image_type($file));
+ }
$mail->setHTMLBody($html);
$mail->setTXTBody($message);
} else {
@@ -89,7 +102,12 @@
$message .= "\n" . sprintf(translate("See this photo in %s"), conf::get("interface.title")) . ": " . getZophURL() . "/photo.php?photo_id=" . $photo_id;
}
$mail->setTXTBody($message);
- $mail->addAttachment($dir . "/" . $file, get_image_type($file));
+ if($annotate) {
+ list($headers,$image)=$photo->display($size);
+ $mail->addAttachmentFromString($image, $photo->get("name"), $headers["Content-type"]);
+ } else {
+ $mail->addAttachmentFromFile($dir . "/" . $file, get_image_type($file));
+ }
}
$mail->setFrom("$from_name <$from_email>");
@@ -103,10 +121,6 @@
}
if (mail($to_email,$subject, $body,$headers)) {
$msg = translate("Your mail has been sent.");
-
- if ($annotate) {
- unlink(ANNOTATE_TEMP_DIR . "/" . $photo->get_annotated_file_name($user));
- }
} else {
$msg = translate("Could not send mail.");
}
@@ -156,14 +170,11 @@
}
}
}
-
- if ($annotate) {
- $photo->annotate($request_vars, $user);
- }
?>
<input type="hidden" name="_action" value="mail">
<input type="hidden" name="photo_id" value="<?php echo $photo_id ?>">
<input type="hidden" name="annotate" value="<?php echo $annotate ?>">
+<input type="hidden" name="annotate_vars" value="<?php echo $annotate_vars ?>">
<label for="html"><?php echo translate("send as html") ?></label>
<?php echo create_pulldown("html", "1", array("1" => translate("Yes",0), "0" => translate("No",0))) ?><br>
<label for="toname"><?php echo translate("to (name)") ?></label>
@@ -191,7 +202,7 @@
<?php
if ($annotate) {
?>
- <img src="image.php?photo_id=<?php echo $photo_id ?>&annotated=1" alt="<?= $photo->get("title") ? $photo->get("title") : $photo->get("name") ?>">
+ <img src="image.php?photo_id=<?php echo $photo_id ?>&annotated=1&<?php echo $annotate_vars ?>" alt="<?= $photo->get("title") ? $photo->get("title") : $photo->get("name") ?>">
<?php
}
else {
View
256 php/photo.inc.php
@@ -36,6 +36,55 @@ function photo($id = 0) {
$this->set("photo_id",$id);
}
+ /**
+ * Display the image
+ * @param string type of image to display mid, thumb or null for full-sized
+ * @return array Return an array that contains:
+ * array headers: the headers
+ * string jpeg: the jpeg file
+ * @todo only supports JPEG currently, should support more filetypes
+ */
+ public function display($type=null) {
+ $headers=array();
+ $name = $this->get("name");
+ $image_path = conf::get("path.images") . "/" . $this->get("path") . "/";
+
+ if ($type) {
+ $image_path .= $type . "/" . $type . "_";
+ }
+ $image_path .= $name;
+
+ $mtime = filemtime($image_path);
+ $filesize = filesize($image_path);
+ $gmt_mtime = gmdate('D, d M Y H:i:s', $mtime) . ' GMT';
+
+ // we assume that the client generates proper RFC 822/1123 dates
+ // (should work for all modern browsers and proxy caches)
+ if(isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) &&
+ $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $gmt_mtime) {
+ header("HTTP/1.1 304 Not Modified");
+ exit;
+ }
+
+ $image_type = get_image_type($image_path);
+ if ($image_type) {
+ $header["Content-Length"] = $filesize;
+ $header["Content-Disposition"]="inline; filename=" . $name;
+ $header["Last-Modified"]=$gmt_mtime;
+ $header["Content-type"]=$image_type;
+ $jpeg=file_get_contents($image_path);
+ return array($header, $jpeg);
+ }
+
+ /**
+ * @todo error handling
+ */
+ }
+
+
+
+
+
function lookup() {
$sql = "SELECT * FROM " . DB_PREFIX . "photos " .
"WHERE photo_id = '" . escape_string($this->get("photo_id")) . "'";
@@ -874,192 +923,6 @@ function) doesn't write it into the exported image file.
return 1;
}
- /*
- * Creates a jpeg photo with
- * text annotation at the bottom.
- *
- * Copyright 2003, Nixon P. Childs
- * License: The same as the rest of Zoph.
- */
- function annotate($vars, $user, $size = 'mid') {
- if ($vars['_size']) {
- $size = $vars['_size'];
- }
-
- if ($size == 'mid') {
- $font = 4;
- $padding = 2;
- $indent = 8;
- }
- else if ($size == 'full') {
- $font = 5;
- $padding = 2;
- $indent = 8;
- }
- else {
- return '';
- }
-
- /* ********************************
- * Read in original image.
- * Need to do now so we know
- * the width of the text lines.
- * ********************************/
-
- $image_path = conf::get("path.images") . $this->get("path");
- if ($size == 'full') {
- $image_path .= "/" . $this->get("name");
- }
- else {
- $image_path .= "/" . $size . "/" . $size . "_" . $this->get("name");
- }
-
- $image_info = getimagesize($image_path);
- switch ($image_info[2]) {
- case 1:
- $orig_image = imagecreatefromgif($image_path);
- break;
- case 2:
- $orig_image = imagecreatefromjpeg($image_path);
- break;
- case 3:
- $orig_image = imagecreatefrompng($image_path);
- break;
- default:
- log::msg("Unsupported image type.", log::ERROR, log::IMG);
- return '';
- }
-
- $row = ImageSY($orig_image) + ($padding/2);
- $maxWidthPixels = ImageSX($orig_image) - (2 * $indent);
- $maxWidthChars = floor($maxWidthPixels / ImageFontWidth($font)) - 1;
-
- /*
- * Sets fields from the given array. Can be used to set vars
- * directly from a GET or POST.
- */
- reset($vars);
- $lines = 0;
- while (list($key, $val) = each($vars)) {
-
- // ignore empty keys or values
- if (empty($key) || $val == "") { continue; }
-
- if (strcmp(Substr($key, strlen($key) - 3), "_cb") == 0) {
-
- /* *****************************************
- * Everthing else uses the checkbox name
- * as the "get" key.
- * *****************************************/
-
- $real_key = Substr($key, 0, strlen($key) - 3);
- $real_val = $vars[$real_key];
-
- /* *****************************************
- * Have to handle title separately because
- * breadcrumbs.inc.php assumes title is
- * the page title.
- * *****************************************/
-
- if ($real_key == "photo_title") {
- $real_key = "title";
- }
- else if ($real_key == "extra") {
- $real_key = $vars["extra_name"];
- }
-
- $out_array[$real_key] = translate($real_key, 0) . ": " .
- $real_val;
- $lines += ceil(strlen($out_array[$real_key]) / $maxWidthChars);
- }
- }
-
- /* **********************************************
- * Create Image
- * In order to create the text area, we must
- * first create the text and determine how much
- * space it requires.
- *
- * I tried implode;wordwrap;explode, but
- * wordwrap doesn't respect \n's in the text.
- * To complicate things, ImageString just
- * renders \n as an upside-down Y.
- *
- * So the current solution is a little awkward,
- * but it works. The only (known) problem is
- * that wrapped lines don't have the same
- * right margin as non-wrapped lines. This is
- * because wordwrap doesn't take into account
- * the line separation string.
- * **********************************************/
-
-
- /*
- $tmpString = implode("\n", $out_array);
-echo ("tmpString:<br>\n" . $tmpString);
- $out_string = wordwrap($tmpString, floor($maxWidthPixels / ImageFontWidth($font)) - 1, "\n ");
-echo ("<br>\noutString:<br>\n" . $out_string);
- $formatted_array = explode("\n", $out_string);
- $lines = sizeof($formatted_array);
- */
-
- $count = 0;
- $final_array=array();
- if ($out_array) {
- while (list($key, $val) = each($out_array)) {
- $tmp_array = explode("\n", wordwrap($val, $maxWidthChars, "\n "));
- while (list($key1, $val1) = each($tmp_array)) {
- $final_array[$count++] = $val1;
- }
- }
- }
-
- $noted_image = ImageCreateTrueColor (ImageSX($orig_image), ImageSY($orig_image) + ((ImageFontHeight($font) + $padding) * $count));
- $white = ImageColorAllocate($noted_image, 255,255, 255);
-
- /* ********************************
- * Use a light grey background to
- * hide the jpeg artifacts caused
- * by the sharp edges in text.
- * ******************************/
-
- $offwhite = ImageColorAllocate($noted_image, 240,240, 240);
- ImageFill($noted_image, 0, ImageSY($orig_image) +1, $offwhite);
- $black = ImageColorAllocate($noted_image, 0, 0, 0);
- ImageColorTransparent($noted_image, $black);
-
- ImageCopy($noted_image, $orig_image, 0, 0, 0, 0, ImageSX($orig_image), ImageSY($orig_image));
-
- if ($final_array) {
- while (list($key, $val) = each($final_array)) {
- ImageString ($noted_image, $font, $indent, $row, $val, $black);
- $row += ImageFontHeight($font) + $padding;
- }
- }
-
- /*
- while (list($key, $val) = each($out_array)) {
- ImageStringWrap ($noted_image, $font, $padding, $row, $val, $black, $maxWidthPixels);
- $row += ImageFontHeight($font) + $padding;
- //echo ($val . "<br>");
- }
- */
-
- //$rnd_name = rand(1, 10000);
- //$temp_name = "zoph" . $user->get("user_id") . "_" . $rnd_name . $photo->get("name");
-
- $temp_name = $this->get_annotated_file_name($user);
- ImageJPEG($noted_image, ANNOTATE_TEMP_DIR . "/" . $temp_name);
- ImageDestroy($orig_image);
- ImageDestroy($noted_image);
-
- return $temp_name;
- }
-
- function get_annotated_file_name($user) {
- return ANNOTATE_TEMP_PREFIX . $user->get("user_id") . "_" . $this->get("name");
- }
-
function getDisplayArray() {
$datetime=$this->get_time(null, "Y-m-d");
@@ -1796,25 +1659,4 @@ function goodrotate($src_img, $degrees = 90) {
return $dst_img;
}
-/*
- * For Nixon Childs' annotate function.
- *
- * Shamelessly stolen from the php.net comment board.
- */
-function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth) {
- $fontwidth = ImageFontWidth($font);
- $fontheight = ImageFontHeight($font);
-
- if ($maxwidth != NULL) {
- $maxcharsperline = floor($maxwidth / $fontwidth);
- $text = wordwrap($text, $maxcharsperline, "\n", 1);
- }
-
- $lines = explode("\n", $text);
- while (list($numl, $line) = each($lines)) {
- ImageString($image, $font, $x, $y, $line, $color);
- $y += $fontheight;
- }
-}
-
?>
View
51 php/util.inc.php
@@ -552,19 +552,6 @@ function valid_image($name) {
return false;
}
-function delete_temp_annotated_files($user_id) {
- if (!ANNOTATE_PHOTOS) {
- return;
- }
-
- $tmp_dir = dir(ANNOTATE_TEMP_DIR);
- $search_str = ANNOTATE_TEMP_PREFIX . $user_id;
- while ($entry = $tmp_dir->read()) {
- if (strpos(" $entry", $search_str) == 1) {
- unlink(ANNOTATE_TEMP_DIR . "/" . $entry);
- }
- }
-}
/* based on urlencode_array
By linus at flowingcreativity dot net
from: http://www.php.net/manual/en/function.urlencode.php
@@ -685,44 +672,6 @@ function get_human($bytes) {
}
}
-function watermark_image($orig, $watermark, $positionX = "center", $positionY = "center", $transparency = 50) {
-
- $wm=imagecreatefromgif($watermark);
-
- $width_orig=ImageSX($orig);
- $height_orig=ImageSY($orig);
-
- $width_wm=ImageSX($wm);
- $height_wm=ImageSY($wm);
-
- switch ($positionX) {
- case "left":
- $destX = 5;
- break;
- case "right":
- $destX = $width_orig - $width_wm - 5;
- break;
- default:
- $destX = ($width_orig / 2) - ($width_wm / 2);
- break;
- }
-
- switch ($positionY) {
- case "top":
- $destY = 5;
- break;
- case "bottom":
- $destY = $height_orig - $height_wm - 5;
- break;
- default:
- $destY = ($height_orig / 2) - ($height_wm / 2);
- break;
- }
- ImageCopyMerge($orig, $wm, $destX, $destY, 0, 0, $width_wm, $height_wm, $transparency);
- imagedestroy($wm);
- return $orig;
-}
-
function pager($current, $total, $num_pages, $page_size, $max_size, $request_vars, $var) {
$url=$_SERVER['PHP_SELF'];
$page_num = floor($current / $page_size) + 1;

1 comment on commit 3f4ab55

@jeroenrnl
Owner

Partly fixes issue 4

#4

Please sign in to comment.
Something went wrong with that request. Please try again.