/*
Application: Image Library for PHP/Applications
Author: Sander Aerts (saerts@saerts.nl)
Version: 1.0 Alpha
Creation date: 25 November 2004
Last modified: 25 November 2004
Copyright © 2004 XSZONE Internet B.V. Netherlands
XSZONE Internet B.V.
Ravenswade 68
3439 LD NIEUWEGEIN
*/
/* Envoirement setups */
define("WIN32TMP", "c:/temp");
define("UNIXTMP", "/tmp");
/* Alignments */
define("LEFT", 1);
define("RIGHT", 2);
define("CENTER", 4);
define("TOP", 8);
define("MIDDLE", 16);
define("BOTTOM", 32);
/* Image class */
class xsImage {
var $img; // Contains image data for the class
var $imgJpeg; // Output Image
var $x; // Image width
var $y; // Image height
var $imgQuality; // Image compression (Jpeg output)
var $__tDiskFile; // Tempory filename for disk access
var $os; // Running OS
/* Constructor */
function xsImage($width, $height, $quality = 100)
{
global $_ENV;
$this->imgQuality = $quality;
$this->x = $width;
$this->y = $height;
/* OS Detection */
if ( !isset($_ENV["OS"]) ) {
$_ENV["OS"] = "UNIX";
}
if ( preg_match("/win/i", $_ENV["OS"]) ) {
// Windows
$this->os = "WIN32";
} else {
// Unix variant
$this->os = "UNIX";
}
}
/* Write to disk tempory */
function diskWrite()
{
if ( $this->os == "WIN32" ) {
/* Win32 */
$this->__tDiskFile = tempnam(WIN32TMP, "xsImageClass");
} else {
/* Unix */
$this->__tDiskFile = tempnam(UNIXTMP, "xsImageClass");
}
error_reporting(0); // Turn of error reporting
ob_start();
Imagepng($this->img);
$this->gd2 = ob_get_contents();
ob_end_clean();
error_reporting(E_ALL); // And back on
$fp = fopen($this->__tDiskFile, "w");
fwrite($fp, $this->gd2);
fclose($fp);
}
/* Restore data back from disk to memory */
function diskRestore()
{
$rbytes = filesize($this->__tDiskFile);
$fp = fopen($this->__tDiskFile, "r");
$gd2Data = fread($fp, $rbytes);
$this->img = ImageCreateFromString($gd2Data);
fclose($fp);
unlink($this->__tDiskFile);
}
/* Reads image data */
function getImage()
{
/* Start output buffer */
error_reporting(E_ALL); // Turn of error reporting
ob_start();
imagejpeg($this->img, '', $this->imgQuality);
$this->imgJpeg = ob_get_contents();
ob_end_clean();
error_reporting(E_ALL); // And back on
return($this->imgJpeg);
}
/* Create decimal colors from an HTML style color */
function hexColors($color)
{
$color = preg_replace("/#/", "", $color);
$res["r"] = hexdec(substr($color, 0, 2));
$res["g"] = hexdec(substr($color, 2, 2));
$res["b"] = hexdec(substr($color, 4, 2));
return($res);
}
/* Check if we need to reverse settings for X and Y axis when creating a vertical image.. */
function reverseXandY($sourcex, $sourcey, $ix, $iy)
{
/* Is the X axis longer then the Y axis */
if ( $sourcex > $sourcey ) {
$_nx = $ix;
$_ny = $iy;
} else {
$_ny = $ix;
$_nx = $iy;
}
return(array($_nx, $_ny));
}
/* Resize image */
function resize($filename, $bgcolor, $bordercolor = "#808080")
{
/* Gets image size of image to scale */
$elements = @getimagesize($filename);
/* Open image with correct open function */
$source = $this->imageGdOpen($filename, $elements[2]);
/* Check image position */
list($this->x, $this->y) = $this->reverseXandY(ImageSX($source), ImageSY($source), $this->x, $this->y);
/* Create a new image */
$this->img = imagecreatetruecolor($this->x, $this->y);
/* Fill image with background color */
$bgcolors = $this->hexColors($bgcolor);
$bgc = imagecolorallocate ($this->img, $bgcolors["r"], $bgcolors["g"], $bgcolors["b"]);
ImageFill($this->img, 0, 0, $bgc);
/* Scale the image.. */
if ( ( ImageSX($source) < $this->x ) && ( ImageSY($source) < $this->y ) ) {
ImageCopyResized( $this->img,
$source,
(($this->x / 2) - (ImageSX($source) / 2)),
(($this->y / 2) - (ImageSY($source) / 2)),
0,
0,
ImageSX($source),
ImageSY($source),
ImageSX($source),
ImageSY($source));
} else {
if ( ImageSX($source) > ImageSY($source) ) {
$_RATIO = (float)(@ImageSX($source) / $this->x);
$_X = (int)(@ImageSX($source) / $_RATIO);
$_Y = (int)(@ImageSY($source) / $_RATIO);
imagecopyresampled( $this->img,
$source,
(($this->x / 2) - ($_X / 2)),
(($this->y / 2) - ($_Y / 2)),
0,
0,
$_X,
$_Y,
ImageSX($source),
ImageSY($source));
} else {
$_RATIO = (float)(@ImageSY($source) / $this->y);
$_X = (int)(@ImageSX($source) / $_RATIO);
$_Y = (int)(@ImageSY($source) / $_RATIO);
imagecopyresampled( $this->img,
$source,
(($this->x / 2) - ($_X / 2)),
(($this->y / 2) - ($_Y / 2)),
0,
0,
$_X,
$_Y,
ImageSX($source),
ImageSY($source));
}
}
/* Add a border if required */
if ( $bordercolor ) {
$brcolors = $this->hexColors($bordercolor);
$brc = imagecolorallocate ($this->img, $brcolors["r"], $brcolors["g"], $brcolors["b"]);
imagerectangle ($this->img, 0, 0, ($this->x - 1), ($this->x - 1), $brc);
}
/* Return true on succes... */
return(true);
}
/* Calculate horizontal image position */
function horizontalPosition($x, $place)
{
/* Horizontal */
switch ( $place ) {
case LEFT:
$res = 0;
break;;
case CENTER:
$res = (int)round(($this->x - $x) / 2);
break;;
case RIGHT:
$res = (int)($this->x - $x);
break;;
default:
die("Don't know how to handle HORIZONTAL position.");
break;;
}
return($res);
}
/* Calculate vertical image position */
function verticalPosition($y, $place)
{
/* Horizontal */
switch ( $place ) {
case TOP:
$res = 0;
break;;
case MIDDLE:
$res = (int)round(($this->y - $y) / 2);
break;;
case BOTTOM:
$res = (int)($this->y - $y);
break;;
default:
die("Don't know how to handle VERTICAL position.");
break;;
}
return($res);
}
/* GD Can Handle? */
function imageGdOpenHandle($type)
{
ob_start();
switch ( $type ) {
case "1":
/* GIF Image found */
$_Q = "imagecreatefromgif(NULL);";
break;;
case "2":
/* JPG Image found */
$_Q = "ImageCreateFromJpeg(NULL);";
break;;
case "3":
/* PNG Image found */
$_Q = "ImageCreateFromPng(NULL);";
break;;
default:
return(false);
break;;
}
eval($_Q);
$message = ob_get_contents();
ob_end_clean();
if ( preg_match("/warning/i", $message) ) {
return(false);
} else {
return(true);
}
}
/* fd2 Open Image */
function imageGdOpen($filename, $type)
{
switch ( $type ) {
case "1":
/* GIF Image found */
$ip = imagecreatefromgif($filename);
break;;
case "2":
/* JPG Image found */
$ip = ImageCreateFromJpeg($filename);
break;;
case "3":
/* PNG Image found */
$ip = ImageCreateFromPng($filename);
break;;
default:
return(false);
break;;
}
return($ip);
}
function addCopyright($filename, $x, $y)
{
/* Calculate position */
list($ix, $iy, $it, $iattr) = getimagesize($filename);
$_x = $this->horizontalPosition($ix, $x);
$_y = $this->verticalPosition($iy, $y);
if ( $this->imageGdOpenHandle($it) ) {
/* Load image to memory */
$clipImage = $this->imageGdOpen($filename, $it);
imagecopy($this->img, $clipImage, $_x, $_y, 0, 0, $ix, $iy);
ImageDestroy($clipImage);
} else {
/* Imagemagick required :) */
$this->diskWrite();
/* Code */
$this->diskRestore();
}
}
}
?>
Dibatel.nl -
| |
|
|
 |
|
Artikelen 0 (0)
€ 0,00
|
|
|
|
|
|
|
|
|
Aanbiedingen:
Beste verkochte producten:
|
|
|
|
|
|
|

|
Copyright © 2014 - dibatel.nl
|
|