Viewing file: image.inc.php (4.96 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
/*
############################################################################
# DWmail
# - version 4.0
# - Copyright (c) 2003-2006 Dominion Web Design
# - http://www.dominion-web.com/products/dwmail/
############################################################################
#
# The contents of this file are subject to the DWmail License version
# 2.2 ('License'). You may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.dominion-web.com/products/dwmail/license.php
# Software distributed under the License is distributed on an "AS IS" basis,
# without warranty of any kind, either express or implied.
#
# This code is Copyright (c) 2003-2006 Dominion Web Design.
# All rights reserved.
#
# This software may not be redistributed outside the terms of the
# license agreement.
#
############################################################################
*/
class GDImage {
var $_mimetype;
var $_tmplocation;
var $_im;
var $_newim;
var $_gifsupport;
var $_pngsupport;
var $_jpgsupport;
function GDImage() {
}
function NewFile($dimension, $whichfix, $mimetype = 'image/pjpeg', $filename = '') {
$this->_mimetype = $mimetype;
if ($filename <> '') {
$this->_tmplocation = $filename;
}
$this->_whichfix = $whichfix;
if ($whichfix == 'h') {
$this->_height = $dimension;
}
else {
$this->_width = $dimension;
}
$this->imgDimensions();
$this->imgResample();
}
function imgSupport() {
$this->_gifsupport = false;
$this->_jpgsupport = false;
$this->_pngsupport = false;
$this->_imgsupport = false;
if (function_exists("imagecreate")) {
// Detect GD first with imagecreate and then check for individual image type support
if (imagetypes() & IMG_GIF) {
$this->_gifsupport = true;
}
if (imagetypes() & IMG_JPG) {
$this->_jpgsupport = true;
}
if (imagetypes() & IMG_PNG) {
$this->_pngsupport = true;
}
$this->_imgsupport = true;
}
}
function ftSupport() {
$this->_ftsupport = false;
if (function_exists("imageftbbox")) {
$this->_ftsupport = true;
}
}
function imgSaveTmpFile($filedata, $filename) {
$filename = strip_tags(str_replace("..", "", $filename));
$fp = fopen ("./tmp/" . $filename, "w");
fputs ($fp, $filedata, strlen($filedata));
fclose ($fp);
$this->_tmplocation = "./tmp/" . $filename;
unset ($filedata);
unset ($filename);
}
function imgRemoveTmpFile() {
unlink ($this->_tmplocation);
}
function imgDimensions() {
list($this->_oldwidth, $this->_oldheight) = getimagesize($this->_tmplocation);
if ($this->_whichfix == 'h') {
$this->_width = round(($this->_oldwidth / ($this->_oldheight / $this->_height)));
}
else {
$this->_height = round(($this->_oldheight / ($this->_oldwidth / $this->_width)));
}
}
function imgResample() {
if ($this->_mimetype == 'image/pjpeg' || $this->_mimetype == 'image/jpeg') {
$this->_im = @imagecreatefromjpeg($this->_tmplocation);
}
elseif ($this->_mimetype == 'image/png') {
$this->_im = @imagecreatefrompng($this->_tmplocation);
}
elseif ($this->_mimetype == 'image/gif') {
$this->_im = @imagecreatefromgif($this->_tmplocation);
}
if ($this->_im) {
// We will out put all images in one format, and depending on which image formats are supported by PHP installation
$this->imgCreateNew();
//echo "w" . $this->_width . " h" . $this->_height . " ow" . $this->_oldwidth . " oh" . $this->_oldheight;
//exit;
imagecopyresampled($this->_newim, $this->_im, 0, 0, 0, 0, $this->_width, $this->_height, $this->_oldwidth, $this->_oldheight);
imagedestroy($this->_im);
if ($this->_jpgsupport == true) {
header("Content-type: image/jpeg");
imagejpeg($this->_newim, '', 100);
}
elseif ($this->_pngsupport == true) {
header("Content-type: image/png");
imagepng($this->_newim);
}
elseif ($this->_gifsupport == true) {
header("Content-type: image/gif");
imagegif($this->_newim);
}
imagedestroy($this->_newim);
}
}
function imgCreateNew() {
$this->_newim = imagecreatetruecolor($this->_width, $this->_height);
}
function imgGenerateHash($string, $width, $height) {
$this->_width = $width;
$this->_height = $height;
$this->imgCreateNew();
$white = ImageColorAllocate($this->_newim, 255, 255, 255);
$black = ImageColorAllocate($this->_newim, 153, 153, 153);
ImageFill($this->_newim, 0, 0, $black);
ImageString($this->_newim, 5, 10, 2, $string, $white);
if ($this->_jpgsupport == true) {
header("Content-type: image/jpeg");
imagejpeg($this->_newim, '', 100);
}
elseif ($this->_pngsupport == true) {
header("Content-type: image/png");
imagepng($this->_newim);
}
elseif ($this->_gifsupport == true) {
header("Content-type: image/gif");
imagegif($this->_newim);
}
imagedestroy($this->_newim);
}
}
?>
|