<?php
include("_config/addCfg.php"); include("_includes/addInc.php"); function hexrgb($hexstr,$rgb='') { $int = hexdec($hexstr); switch($rgb) { case "r": return 0xFF & $int >> 0x10; break; case "g": return 0xFF & ($int >> 0x8); break; case "b": return 0xFF & $int; break; default: return array( "r" => 0xFF & $int >> 0x10, "g" => 0xFF & ($int >> 0x8), "b" => 0xFF & $int ); break; } } $vertical=($R['dir']=='Y'); $allowedDimensions=Array( 100=>true, 50=>true, 10=>true, 5=>true, 1=>true, ); $allowedLineDimensions=$allowedDimensions; $w=$R['w']; $h=$R['h']; $w=($w?max($w,0):1); $h=($h?max($h,0):1); $w+=round(26*1.3); $h+=round(26*1.3); $w=min(8192,$w); $h=min(8192,$h); $gridCt=($S[$thisSection]['page']['gridCt']?$S[$thisSection]['page']['gridCt']:$CFG['DTM']['module']['gridCt']); $zoom=$S[$thisSection]['page']['zoom']; if(mm2px(100)<300){ $allowedDimensions[1]=false; if(mm2px(100)<200){ $allowedDimensions[5]=false; $allowedLineDimensions[1]=false; if(mm2px(100)<100){ $allowedDimensions[10]=false; $allowedLineDimensions[5]=false; } } } if($vertical){ $w=26; }else{ $h=26; } $outputFile="makeRuler_".($vertical?'Y':'X').".{$w}x{$h}@".mm2px(100); $outputFile=readCachedFile($outputFile); $image=imagecreate($w, $h); $color='ffffff'; $colorWhite=imagecolorallocate($image, hexrgb($color,'r'), hexrgb($color,'g'), hexrgb($color,'b')); $color='bfbfbf'; $colorGrey[2]=imagecolorallocate($image, hexrgb($color,'r'), hexrgb($color,'g'), hexrgb($color,'b')); $color='808080'; $colorGrey[1]=imagecolorallocate($image, hexrgb($color,'r'), hexrgb($color,'g'), hexrgb($color,'b')); $color='000000'; $colorGrey[0]=imagecolorallocate($image, hexrgb($color,'r'), hexrgb($color,'g'), hexrgb($color,'b')); $color='000000'; $colorBlack=imagecolorallocate($image, hexrgb($color,'r'), hexrgb($color,'g'), hexrgb($color,'b')); $units['mm']=$gridCt*$zoom; $unit=$units['mm']; $period=$unit; $size['width']=px2mm($w); $size['height']=px2mm($h); $multimples=Array( '100'=>$colorGrey[0], '50'=>$colorGrey[0], '10'=>$colorGrey[0], '5'=>$colorGrey[1], '1'=>$colorGrey[2], ); $border=25; $heights=Array( '100'=>$border*0.40 , '50'=>$border*0.40 , '10'=>$border*0.40 , '5'=> $border*0.60 , '1'=> $border*0.80 , ); $fontColor=Array( '100'=>$colorGrey[0], '50'=>$colorGrey[1], '10'=>$colorGrey[2], '5'=>0, '1'=>0, ); $offsetX=25; $offsetY=-2; $dimensionX=25; $dimensionY=24; imagefill($image, 0, 0,$colorWhite); if(!$vertical){ imageline($image, $offsetX+0, 0, $offsetX+0, $border, $colorBlack); imageline($image, 0, $dimensionY, $offsetX, $dimensionY, $colorBlack); imageline($image, $offsetX+0, $border-1, $offsetX+$w, $border-1, $colorBlack); for($i=0;$i<$size['width'];$i++){ $x1=round($offsetX+($i*$period)); $x2=$x1; $y1=0; $y2=$dimensionY-2; foreach($multimples as $index=>$multiple){ if($i % $index == 0){ $currentPoint=sprintf("%.0f",$i/10); $y1=$heights[$index]; if($fontColor[$index] && $currentPoint!=$lastPoint && $allowedDimensions[$index]){ if($currentPoint==0){ $textWidth=1*5; imagestring($image,4,$x1-10,9,$currentPoint,$fontColor[10]); }else{ $textWidth=strlen($currentPoint)*5; imagestring($image,2,round($x1-$textWidth/2),-2,$currentPoint,$fontColor[$index]); } } if($index%10==0)$y2=$dimensionY; if($allowedLineDimensions[$index]){ imageline($image, $x1, $y1, $x2, $y2, $multimples[$index]); } break; } $coloridx++; } } } if($vertical){ imageline($image, $offsetX, $offsetY, $offsetX, $offsetY+$h, $colorBlack); for($i=0;$i<$size['height'];$i++){ $x2=$offsetX-2; $y1=round($offsetY+($i*$period)); $y2=$y1; foreach($multimples as $index=>$multiple){ if($i % $index == 0){ $currentPoint=sprintf("%.0f",$i/10); $x1=$heights[$index]; if($fontColor[$index] && $currentPoint!=$lastPoint && $allowedDimensions[$index]){ if($currentPoint==0){ $textWidth=1*5; imagestring($image,4,$x1+6,$y1-15,$currentPoint,$fontColor[10]); }else{ $textWidth=strlen($currentPoint)*5; imagestringup($image,2,round($x1-$dimensionX/2),round($y1+$textWidth/2),$currentPoint,$fontColor[$index]); } } if($index%10==0)$x2=$dimensionX; if($allowedLineDimensions[$index]){ imageline($image, $x1, $y1, $x2, $y2, $multimples[$index]); } break; } $coloridx++; } } } switch($CFG['DTM']['imageCache']['output']){ case 'png': if($CFG['DTM']['imageCache']['enabled']) imagepng($image,$outputFile); header("Content-type: image/png"); imagepng($image); break; case 'jpg': if($CFG['DTM']['imageCache']['enabled']) imagejpeg($image,$outputFile,65); header("Content-type: image/jpeg"); imagejpeg($image); break; case 'gif': if($CFG['DTM']['imageCache']['enabled']) imagegif($image,$outputFile); header("Content-type: image/gif"); imagegif($image); break; } imagedestroy($image); 