00001 <?php
00002 require_once
TM_PATH . 'constants.php';
00003 require_once
TM_PATH . 'juelich/JuelichGlobals.php';
00004
00016 class JuelichImage {
00017
00018 var
$type =
"text/plain";
00019 var
$image;
00020 var
$success =
false;
00026 function
JuelichImage() {
00027 $data =&
getDataInstance();
00028
$path = explode(
'/', $data->getPathInfo());
00029
if (count($path) != 3) {
00030 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00031 $error =
new JuelichError;
00032 $error->printError(5,
00033 'Image-URL hat falsche Parameterzahl: '
00034 . implode(
'/', $path));
00035
exit();
00036 }
00037 $mode =
$path[0];
00038 $id =
$path[1];
00039
00040
if ($mode ==
'p' || $mode == 'ps' || $mode ==
'z') {
00041 $this->
getImage($mode, $
id);
00042 }
00043
else {
00044 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00045 $error =
new JuelichError;
00046 $error->printError(5,
00047 'Image-URL, unbekannter Modus: '
00048 . $mode);
00049
exit();
00050 }
00051
if ($this->
success) {
00052 $this->type = 'image/jpeg';
00053 }
00054
return;
00055 }
00056
00061 function
getContentType() {
00062
return $this->type;
00063 }
00064
00070 function
deliverImage() {
00071
if ($this->
success) {
00072 imagejpeg($this->image, '', 100);
00073 }
00074 }
00075
00083 function
getImage($mode, $
id) {
00084 $imgFs =
IMG_CACHE_DIR .
'/' . $mode . $id . '.jpg';
00085 $imgDb =
'p' . $id;
00086
if ($mode ==
'z') {
00087 $imgDb =
'z' . $id;
00088 }
00089
if (file_exists($imgFs)) {
00090 $this->image = imagecreatefromjpeg($imgFs);
00091
if (empty($this->image)) {
00092 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00093 $error =
new JuelichError;
00094 $error->printError(4,
00095 'Image kann nicht erzeugt werden (FS): '
00096 . $imgFs);
00097
exit();
00098 }
00099 $this->
success =
true;
00100
return;
00101 }
00102
$db =&
getDbReaderInstance();
00103 $iData = array();
00104
$db->getImage($imgDb, $iData);
00105
if (empty($iData)) {
00106 include_once
TM_PATH . 'juelich/web/
JuelichError.php';
00107 $error =
new JuelichError;
00108 $error->printError(5,
00109 'Image nicht in der DB enthalten: '
00110 . $imgDb);
00111
exit();
00112 }
00113 $this->image = imagecreatefromstring($iData['i_data']);
00114
if (empty($this->image)) {
00115 $error->printError(4,
00116 'Image kann nicht erzeugt werden (DB): '
00117 . $imgDb);
00118
exit();
00119 }
00120
if ($mode == 'ps') {
00121 $this->
success = $this->
makeThumbnail();
00122 }
00123 $this->
success = imagejpeg($this->image, $imgFs, 100);
00124
return;
00125 }
00126
00132 function
makeThumbnail() {
00133 $imgBig = $this->image;
00134 $wBig = imagesx($imgBig);
00135 $hBig = imagesy($imgBig);
00136
00137 $wThumb = 0;
00138 $hThumb = 0;
00139 $need =
false;
00140
if ($wBig >= $hBig && $wBig > 100) {
00141 $wThumb = 100;
00142 $hThumb = round($hBig / ($wBig / 100), 0);
00143 $need =
true;
00144 }
00145 elseif ($hBig > 100) {
00146 $wThumb = round($wBig / ($hBig / 100), 0);
00147 $hThumb = 100;
00148 $need =
true;
00149 }
00150
if (!$need) {
00151
return true;
00152 }
00153 $imgThumb = imagecreatetruecolor($wThumb, $hThumb);
00154 imagecopyresampled($imgThumb,
00155 $imgBig,
00156 0,
00157 0,
00158 0,
00159 0,
00160 $wThumb,
00161 $hThumb,
00162 $wBig,
00163 $hBig);
00164 imagedestroy($imgBig);
00165 $this->image = $imgThumb;
00166
return true;
00167 }
00168
00169 }
00170
00171 ?>