<?php
#
# phpWebDesk Transparent Conversion
# (c) 2003 Andrew Godwin
#
# Ok, so I'm using ImageMagick. Why reinvent the wheel?
#
# Modes
# Basic functionality for this at the moment. You've got input in TML
# (Transferable Markup Language; like HTML, only different) and output
# in HTML (hmmm...) WML (WAP Markup Language. One of my inspirations for this)
# and plain ASCII text with things like *italic* and !bold!. Don't know about those
# last formatting things, may take 'em off or put them in a seperate mode.
#
# 0 - PNG (default)
# 1 - JPEG
# 2 - GIF (Warning - may still be legal issues)
# 3 - BMP
# 4 - WBMP (default for WAP browsers)
// Catch null filenames / random pagecalls
if (!file_exists($if)) { die("A valid filename (in the 'if' variable) would be nice.");}
// Generate md5 hash to use as new filename (because we can refer back to it)
$ofilen = md5_file($if);
// Find out IM's type code (i.e. png: or jpeg:) and the file extension.
switch ($mode) {
case 0:
$typecode="png";
$typeext="png";
break;
case 1:
$typecode="jpeg";
$typeext="jpg";
break;
case 2:
$typecode="gif";
$typeext="gif";
break;
case 3:
$typecode="bmp";
$typeext="bmp";
break;
}
// Call ImageMagick to convert the file.
$comline = "convert.exe ".$if." ".$typecode.":".$ofilen.".".$typeext;
exec($comline);
// Send header - i'm relying on the typecode being the same as the mime type for now.
header("Content-type: image/".$typecode);
// Open our file
$ofile = $ofilen.".".$typeext;
$i = 0;
while(!file_exists($ofile)) {
$i++;
if($i>99) {die;}
$ofile = $ofilen.".".$typeext.".".$i;
}
readfile($ofile);
@unlink($ofile);
for($i=0;$i<99;$i++){
$ofile = $ofilen.".".$typeext.".".$i;
@unlink($ofile);
}
?>