query("select * from " . $SYSTEM['db_prefix'] . "_img_cache where qid='" . $db->query($qid) . "'"); }; $fromCache = 0; if($SYSTEM['img_cache'] && $_REQUEST['resize']!='' && $cacheQ->num_rows) { $cacheR = $cacheQ->row; if(strlen($cacheR['img'])>1024) { $fromCache = 1; }; }; if($fromCache && $SYSTEM['img_cache']) { $outputIMG = $cacheR['img']; } else { if($_REQUEST['class']=='img') { if($_REQUEST['id']!='') $COMMIT=1; $QUERY = "select img from " . $SYSTEM['db_prefix'] . "_img_images where id=" . (int) $_REQUEST['id']; $COL = 'img'; if($SYSTEM['blob_filestore']) { $FILE = '../bindata/' . (int) $_REQUEST['id'] . '.jpg'; if($SYSTEM['blob_filestore_migration'] && !file_exists($FILE)) { $rx = $db->query($QUERY); $rx = $rx->row; $imagedata = $rx[$COL]; file_put_contents($FILE, $imagedata, LOCK_EX); $db->query("update " . $SYSTEM['db_prefix'] . "_img_images set img='' where id=" . (int) $_REQUEST['id']); }; $QUERY=null; } else if($SYSTEM['blob_filestore_migration'] && file_exists('../bindata/' . (int)$_REQUEST['id'] . '.jpg')) { $imagedata = file_get_contents('../bindata/' . (int) $_REQUEST['id'] . '.jpg'); $db->query("update " . $SYSTEM['db_prefix'] . "_img_images set img='" . $db->escape($imagedata) . "' where id=" . (int) $_REQUEST['id']); unlink('../bindata/' . (int) $_REQUEST['id'] . '.jpg'); }; $PX=64; $PY=64; $CR=255; $CG=255; $CB=255; }; if($_REQUEST['class']=='news'){ if($_REQUEST['id'] != '') { $COMMIT = 1; } $QUERY = "select img from ".$SYSTEM['db_prefix']."_news_data where id=".(int)$_REQUEST['id']; $COL='img'; if($SYSTEM['blob_filestore']) { $FILE = '../bindata/ni-' . (int) $_REQUEST['id'] . '.jpg'; if($SYSTEM['blob_filestore_migration'] && !file_exists($FILE)) { $rx = $db->query($QUERY); $rx = $rx->row; $imagedata = $rx[$COL]; file_put_contents($FILE, $imagedata, LOCK_EX); $db->query("update " . $SYSTEM['db_prefix'] . "_news_data set img = '' where id=" . (int) $_REQUEST['id']); } $QUERY = null; } else if($SYSTEM['blob_filestore_migration'] && file_exists('../bindata/ni-' . (int) $_REQUEST['id'] . '.jpg')) { $imagedata = file_get_contents('../bindata/ni-' . (int) $_REQUEST['id'] . '.jpg'); $db->query("update " . $SYSTEM['db_prefix'] . "_news_data set img='" . $db->escape($imagedata) . "' where id=" . (int) $_REQUEST['id']); unlink('../bindata/ni-' . (int) $_REQUEST['id'] . '.jpg'); } $PX=64; $PY=64; $CR=255; $CG=255; $CB=255; }; if($_REQUEST['class']=='extern'){ $COMMIT=1; $EXTERN=1; $PX=64; $PY=64; $CR=255; $CG=255; $CB=255; }; if($_REQUEST['color']!='') { $COLOR=$_REQUEST['color']; $color=hexdec($COLOR); $CB=($color%256); $CG=(floor($color/256)%256); $CR=(floor($color/65536)%256); }; if($COMMIT && !$EXTERN && !$FILE) { $q = $db->query($QUERY); }; if(!$COMMIT || (!$EXTERN && !$FILE && !$q->num_rows) || ($FILE && !file_exists($FILE))) { $IMG=blankimage($PX,$PY,$CR,$CG,$CB); } else { if($EXTERN){ $image=http_get_content($_REQUEST['src']); } else if($FILE){ $image=file_get_contents($FILE); } else { $r = $q->row; $image=$r[$COL]; }; header("Content-type: image/jpeg"); if(strlen($image)>0) { $IMG = imagecreatefromstring($image); } else { if($ALT != '') { $IMG = imagecreatefromjpeg($ALT); } else { $IMG = blankimage($PX,$PY,$CR,$CG,$CB); }; }; }; if($FORMAT=='png'){ imagealphablending($IMG, false); imagesavealpha($IMG, true); }; if($FORMAT=='gif'){ $transColor=imagecolorallocate($IMG,255, 0, 255); for($x = 0; $x < imagesx($IMG); $x++){ for($y = 0; $y < imagesy($IMG); $y++){ $alpha = (imagecolorat($IMG,$x,$y) & 0x7F000000) >> 24;//127 is completely TRANSPARENT, 0 opaque //DITHER! if($alpha>13&&($alpha >=127-13 || (rand(0,127))>=(127-$alpha))){ imagesetpixel($IMG,$x,$y,$transColor); }; }; }; }; if($_REQUEST['resize'] == '1') { $imgs=$IMG; $isx=imagesx($imgs); $isy=imagesy($imgs); $idx=$_REQUEST['sx']; $idy=$_REQUEST['sy']; $imgd=imagecreatetruecolor($idx,$idy); if($FORMAT=='png' || $FORMAT=='gif'){ imagealphablending($imgd, false); imagesavealpha($imgd, true); imagefill($imgd, 0, 0, imagecolorallocatealpha($imgd, 0,0,0,127)); }; if($FORMAT=='gif'){ imagefill($imgd, 0, 0, $transColor); }; if($FORMAT=='jpeg'){ imagefill($imgd, 0, 0, imagecolorallocate($imgd,$CR, $CG, $CB)); }; if($FORMAT=='gif'){ imagecopyresized($imgd,$imgs,0,0,0,0,$idx,$idy,$isx,$isy); } else { imagecopyresampled($imgd,$imgs,0,0,0,0,$idx,$idy,$isx,$isy); }; $IMG=$imgd; }; if($_REQUEST['resize'] == '2' || $_REQUEST['resize'] == '2t') { $imgs=$IMG; $isx=imagesx($imgs); $isy=imagesy($imgs); $ism=max($isx,$isy); $idm=$_REQUEST['size']; $k=$idm/$ism; $idx=round($k*$isx); $idy=round($k*$isy); $ids=max($idx,$idy); $imgd=imagecreatetruecolor($ids,$ids); if($FORMAT=='png' || $FORMAT=='gif'){ imagealphablending($imgd, false); imagesavealpha($imgd, true); imagefill($imgd, 0, 0, imagecolorallocatealpha($imgd, 0,0,0,127)); }; if($FORMAT=='gif'){ imagefill($imgd, 0, 0, $transColor); }; if($FORMAT=='jpeg'){ imagefill($imgd, 0, 0, imagecolorallocate($imgd, $CR, $CG, $CB)); }; $dx=0;$dy=0; if($idx>=$idy){ $dy=floor(($idx-$idy)/2); }; if($idx<$idy){ $dx=floor(($idy-$idx)/2); }; if($_REQUEST['resize']=='2t'){ $dy=0; }; if($FORMAT=='gif'){ imagecopyresized($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); } else { imagecopyresampled($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); }; $IMG=$imgd; }; if($_REQUEST['resize'] == '3') { $imgs=$IMG; $isx=imagesx($imgs); $isy=imagesy($imgs); $isk=$isx/$isy; $ifx=$_REQUEST['sx']; $ify=$_REQUEST['sy']; $ifk=$ifx/$ify; if($ifk>$isk){ $k=$isy/$ify; $idy=$ify; $idx=ceil($isx/$k); $dx=floor(($ifx-$idx)/2); $dy=0; } else { $k=$isx/$ifx; $idx=$ifx; $idy=ceil($isy/$k); $dy=floor(($ify-$idy)/2); $dx=0; }; $COLOR='fcfac7'; if($_REQUEST['color']!='') $COLOR=$_REQUEST['color']; $color=hexdec($COLOR); $CB=($color%256); $CG=(floor($color/256)%256); $CR=(floor($color/65536)%256); $imgd=imagecreatetruecolor($ifx,$ify); if($FORMAT=='png' || $FORMAT=='gif'){ imagealphablending($imgd, false); imagesavealpha($imgd, true); imagefill($imgd, 0, 0, imagecolorallocatealpha($imgd, 0,0,0,127)); }; if($FORMAT=='gif'){ imagefill($imgd, 0, 0, $transColor); }; if($FORMAT=='jpeg'){ imagefill($imgd, 0, 0, imagecolorallocate($imgd, $CR, $CG, $CB)); }; if($FORMAT=='gif'){ imagecopyresized($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); } else { imagecopyresampled($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); }; $IMG=$imgd; }; if($_REQUEST['resize'] == '4') { $imgs=$IMG; $isx=imagesx($imgs); $isy=imagesy($imgs); $isk=$isx/$isy; $ifx=$_REQUEST['sx']; $ify=$_REQUEST['sy']; $ifk=$ifx/$ify; if($ifk>$isk){ $k=$isy/$ify; $idy=$ify; $idx=ceil($isx/$k); $dx=floor(($ifx-$idx)/2); $dy=0; } else { $k=$isx/$ifx; $idx=$ifx; $idy=ceil($isy/$k); $dy=floor(($ify-$idy)/2); $dx=0; }; $imgd=imagecreatetruecolor($idx,$idy); if($FORMAT=='png'){ imagealphablending($imgd, false); imagesavealpha($imgd, true); }; if($FORMAT=='gif'){ imagecopyresized($imgd,$imgs,0,0,0,0,$idx,$idy,$isx,$isy); } else { imagecopyresampled($imgd,$imgs,0,0,0,0,$idx,$idy,$isx,$isy); }; $IMG=$imgd; }; if($_REQUEST['resize'] == '5') { $imgs = $IMG; $isx = imagesx($imgs); $isy = imagesy($imgs); $isk = $isx/$isy; $ifx = $_REQUEST['sx']; $ify = $_REQUEST['sy']; $ifk = $ifx/$ify; if($ifk < $isk) { $k = $isy/$ify; $idy = $ify; $idx = ceil($isx/$k); $dx = floor(($ifx-$idx)/2); $dy = 0; } else { $k = $isx/$ifx; $idx = $ifx; $idy = ceil($isy/$k); $dy = floor(($ify-$idy)/2); $dx = 0; }; $COLOR = 'fcfac7'; if($_REQUEST['color']!='') $COLOR=$_REQUEST['color']; $color=hexdec($COLOR); $CB=($color%256); $CG=(floor($color/256)%256); $CR=(floor($color/65536)%256); $imgd=imagecreatetruecolor($ifx,$ify); if($FORMAT=='png'){ imagealphablending($imgd, false); imagesavealpha($imgd, true); }; imagefill($imgd, 0, 0, imagecolorallocate($imgd, $CR, $CG, $CB)); if($FORMAT=='gif'){ imagecopyresized($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); } else { imagecopyresampled($imgd,$imgs,$dx,$dy,0,0,$idx,$idy,$isx,$isy); }; $IMG=$imgd; }; ob_start(); if($FORMAT=='jpeg'){ imagejpeg($IMG,NULL,$QUALITY); }; if($FORMAT=='png'){ imagepng($IMG); }; if($FORMAT=='gif'){ imagecolortransparent($IMG, $transColor); imagegif($IMG); }; $outputIMG = ob_get_contents(); ob_end_clean(); if($_REQUEST['resize'] != '' && $SYSTEM['img_cache']) { ob_start(); $db->query("delete from " . $SYSTEM['db_prefix'] . "_img_cache where qid='" . $db->escape($qid) . "'"); $db->query("insert into " . $SYSTEM['db_prefix'] . "_img_cache (`qid`,`img`) values ('" . $db->escape($qid) . "','" . $db->escape($outputIMG) . "')"); ob_end_clean(); } } echo($outputIMG); // Exiting code to prevent creating cached image if (http_response_code() == 404) { exit; } ?>