- Timestamp:
- Apr 13, 2019, 8:05:15 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/modules/Elezioni/grafici/jpgraph_imgtrans.php
r2 r265 1 1 <?php 2 2 //======================================================================= 3 // File: 4 // Description: 5 // Created: 6 // Ver: $Id: jpgraph_imgtrans.php 781 2006-10-08 08:07:47Z ljp $3 // File: JPGRAPH_IMGTRANS.PHP 4 // Description: Extension for JpGraph to do some simple img transformations 5 // Created: 2003-09-06 6 // Ver: $Id: jpgraph_imgtrans.php 1106 2009-02-22 20:16:35Z ljp $ 7 7 // 8 // Copyright (c) A ditus Consulting. All rights reserved.8 // Copyright (c) Asial Corporation. All rights reserved. 9 9 //======================================================================== 10 10 11 11 //------------------------------------------------------------------------ 12 12 // Class ImgTrans 13 // Perform some simple image transformations. 13 // Perform some simple image transformations. 14 14 //------------------------------------------------------------------------ 15 15 class ImgTrans { 16 16 private $gdImg=null; 17 17 18 function ImgTrans($aGdImg) {19 20 21 } 22 23 // -------------------------------------------------------------------- 24 // _TransVert3D() and _TransHor3D() are helper methods to 25 // Skew3D(). 18 function __construct($aGdImg) { 19 // Constructor 20 $this->gdImg = $aGdImg; 21 } 22 23 // -------------------------------------------------------------------- 24 // _TransVert3D() and _TransHor3D() are helper methods to 25 // Skew3D(). 26 26 // -------------------------------------------------------------------- 27 27 function _TransVert3D($aGdImg,$aHorizon=100,$aSkewDist=120,$aDir=SKEW3D_DOWN,$aMinSize=true,$aFillColor='#FFFFFF',$aQuality=false,$aBorder=false,$aHorizonPos=0.5) { 28 28 29 29 30 31 32 33 //("Value for image transformation out of bounds.\nVanishing point on horizon must be specified as a value between 0 and 1.");34 35 36 37 38 39 40 41 if( $aMinSize ) 42 43 else 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 for($y=0; $y < $h; ++$y) { 60 61 62 $yt = floor($yp * $aHorizon / ($aSkewDist + $yp)); 63 64 65 66 67 68 69 for($x=0; $x < $w; ++$x) { 70 71 if( $aDir == SKEW3D_UP ) 72 73 74 75 76 77 $b = $rgb & 0xFF; 78 $colidx = imagecolorallocate($newgdh,$r,$g,$b); 79 80 81 82 83 84 85 86 87 88 89 90 91 $nb = $nrgb & 0xFF; 92 93 floor(($g+$ng)/2),floor(($b+$nb)/2)); 94 } 95 96 imagesetpixel($newgdh,$xt,$syt,$colidx); 97 98 99 $set[$yt] = true; 100 101 102 103 } 104 105 // -------------------------------------------------------------------- 106 // _TransVert3D() and _TransHor3D() are helper methods to 107 // Skew3D(). 30 // Parameter check 31 if( $aHorizonPos < 0 || $aHorizonPos > 1.0 ) { 32 JpGraphError::RaiseL(9001); 33 //("Value for image transformation out of bounds.\nVanishing point on horizon must be specified as a value between 0 and 1."); 34 } 35 36 $w = imagesx($aGdImg); 37 $h = imagesy($aGdImg); 38 39 // Create new image 40 $ww = $w; 41 if( $aMinSize ) 42 $hh = ceil($h * $aHorizon / ($aSkewDist+$h)); 43 else 44 $hh = $h; 45 46 $newgdh = imagecreatetruecolor($ww,$hh); 47 $crgb = new RGB( $newgdh ); 48 $fillColor = $crgb->Allocate($aFillColor); 49 imagefilledrectangle($newgdh,0,0,$ww-1,$hh-1,$fillColor); 50 51 if( $aBorder ) { 52 $colidx = $crgb->Allocate($aBorder); 53 imagerectangle($newgdh,0,0,$ww-1,$hh-1,$colidx); 54 } 55 56 $mid = round($w * $aHorizonPos); 57 58 $last=$h; 59 for($y=0; $y < $h; ++$y) { 60 61 $yp = $h-$y-1; 62 $yt = floor($yp * $aHorizon / ($aSkewDist + $yp)); 63 64 if( !$aQuality ) { 65 if( $last <= $yt ) continue ; 66 $last = $yt; 67 } 68 69 for($x=0; $x < $w; ++$x) { 70 $xt = ($x-$mid) * $aSkewDist / ($aSkewDist + $yp); 71 if( $aDir == SKEW3D_UP ) 72 $rgb = imagecolorat($aGdImg,$x,$h-$y-1); 73 else 74 $rgb = imagecolorat($aGdImg,$x,$y); 75 $r = ($rgb >> 16) & 0xFF; 76 $g = ($rgb >> 8) & 0xFF; 77 $b = $rgb & 0xFF; 78 $colidx = imagecolorallocate($newgdh,$r,$g,$b); 79 $xt = round($xt+$mid); 80 if( $aDir == SKEW3D_UP ) { 81 $syt = $yt; 82 } 83 else { 84 $syt = $hh-$yt-1; 85 } 86 87 if( !empty($set[$yt]) ) { 88 $nrgb = imagecolorat($newgdh,$xt,$syt); 89 $nr = ($nrgb >> 16) & 0xFF; 90 $ng = ($nrgb >> 8) & 0xFF; 91 $nb = $nrgb & 0xFF; 92 $colidx = imagecolorallocate($newgdh,floor(($r+$nr)/2), 93 floor(($g+$ng)/2),floor(($b+$nb)/2)); 94 } 95 96 imagesetpixel($newgdh,$xt,$syt,$colidx); 97 } 98 99 $set[$yt] = true; 100 } 101 102 return $newgdh; 103 } 104 105 // -------------------------------------------------------------------- 106 // _TransVert3D() and _TransHor3D() are helper methods to 107 // Skew3D(). 108 108 // -------------------------------------------------------------------- 109 109 function _TransHor3D($aGdImg,$aHorizon=100,$aSkewDist=120,$aDir=SKEW3D_LEFT,$aMinSize=true,$aFillColor='#FFFFFF',$aQuality=false,$aBorder=false,$aHorizonPos=0.5) { 110 110 111 112 113 114 115 116 if( $aMinSize ) 117 118 else 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 $last = -1; 134 for($x=0; $x < $w-1; ++$x) { 135 136 137 138 139 140 141 for($y=0; $y < $h; ++$y) { 142 143 144 145 if( $aDir == SKEW3D_RIGHT ) 146 147 148 149 150 151 $b = $rgb & 0xFF; 152 $colidx = imagecolorallocate($newgdh,$r,$g,$b); 153 154 155 156 157 158 159 160 161 162 163 164 $nb = $nrgb & 0xFF; 165 166 floor(($g+$ng)/2),floor(($b+$nb)/2)); 167 168 imagesetpixel($newgdh,$sxt,$yt,$colidx); 169 170 171 172 173 174 111 $w = imagesx($aGdImg); 112 $h = imagesy($aGdImg); 113 114 // Create new image 115 $hh = $h; 116 if( $aMinSize ) 117 $ww = ceil($w * $aHorizon / ($aSkewDist+$w)); 118 else 119 $ww = $w; 120 121 $newgdh = imagecreatetruecolor($ww,$hh); 122 $crgb = new RGB( $newgdh ); 123 $fillColor = $crgb->Allocate($aFillColor); 124 imagefilledrectangle($newgdh,0,0,$ww-1,$hh-1,$fillColor); 125 126 if( $aBorder ) { 127 $colidx = $crgb->Allocate($aBorder); 128 imagerectangle($newgdh,0,0,$ww-1,$hh-1,$colidx); 129 } 130 131 $mid = round($h * $aHorizonPos); 132 133 $last = -1; 134 for($x=0; $x < $w-1; ++$x) { 135 $xt = floor($x * $aHorizon / ($aSkewDist + $x)); 136 if( !$aQuality ) { 137 if( $last >= $xt ) continue ; 138 $last = $xt; 139 } 140 141 for($y=0; $y < $h; ++$y) { 142 $yp = $h-$y-1; 143 $yt = ($yp-$mid) * $aSkewDist / ($aSkewDist + $x); 144 145 if( $aDir == SKEW3D_RIGHT ) 146 $rgb = imagecolorat($aGdImg,$w-$x-1,$y); 147 else 148 $rgb = imagecolorat($aGdImg,$x,$y); 149 $r = ($rgb >> 16) & 0xFF; 150 $g = ($rgb >> 8) & 0xFF; 151 $b = $rgb & 0xFF; 152 $colidx = imagecolorallocate($newgdh,$r,$g,$b); 153 $yt = floor($hh-$yt-$mid-1); 154 if( $aDir == SKEW3D_RIGHT ) { 155 $sxt = $ww-$xt-1; 156 } 157 else 158 $sxt = $xt ; 159 160 if( !empty($set[$xt]) ) { 161 $nrgb = imagecolorat($newgdh,$sxt,$yt); 162 $nr = ($nrgb >> 16) & 0xFF; 163 $ng = ($nrgb >> 8) & 0xFF; 164 $nb = $nrgb & 0xFF; 165 $colidx = imagecolorallocate($newgdh,floor(($r+$nr)/2), 166 floor(($g+$ng)/2),floor(($b+$nb)/2)); 167 } 168 imagesetpixel($newgdh,$sxt,$yt,$colidx); 169 } 170 171 $set[$xt] = true; 172 } 173 174 return $newgdh; 175 175 } 176 176 … … 180 180 // of the image. The transformation is specified by giving the height 181 181 // of the artificial horizon and specifying a "skew" factor which 182 // is the distance on the horizon line between the point of 182 // is the distance on the horizon line between the point of 183 183 // convergence and perspective line. 184 184 // … … 188 188 // Parameters: 189 189 // * $aGdImg, GD handle to the image to be transformed 190 // * $aHorizon, Distance to the horizon 190 // * $aHorizon, Distance to the horizon 191 191 // * $aSkewDist, Distance from the horizon point of convergence 192 // on the horizon line to the perspective points. A larger 192 // on the horizon line to the perspective points. A larger 193 193 // value will fore-shorten the image more 194 // * $aDir, parameter specifies type of convergence. This of this 194 // * $aDir, parameter specifies type of convergence. This of this 195 195 // as the walls in a room you are looking at. This specifies if the 196 196 // image should be applied on the left,right,top or bottom walls. … … 202 202 // high quality will have a dramatic effect on the time it takes 203 203 // to transform an image. 204 // * $aBorder, if set to anything besides false this will draw a 204 // * $aBorder, if set to anything besides false this will draw a 205 205 // a border of the speciied color around the image 206 206 // -------------------------------------------------------------------- 207 207 function Skew3D($aHorizon=120,$aSkewDist=150,$aDir=SKEW3D_DOWN,$aHiQuality=false,$aMinSize=true,$aFillColor='#FFFFFF',$aBorder=false) { 208 209 208 return $this->_Skew3D($this->gdImg,$aHorizon,$aSkewDist,$aDir,$aHiQuality, 209 $aMinSize,$aFillColor,$aBorder); 210 210 } 211 211 212 212 function _Skew3D($aGdImg,$aHorizon=120,$aSkewDist=150,$aDir=SKEW3D_DOWN,$aHiQuality=false,$aMinSize=true,$aFillColor='#FFFFFF',$aBorder=false) { 213 214 215 216 217 218 } 219 213 if( $aDir == SKEW3D_DOWN || $aDir == SKEW3D_UP ) 214 return $this->_TransVert3D($aGdImg,$aHorizon,$aSkewDist,$aDir,$aMinSize,$aFillColor,$aHiQuality,$aBorder); 215 else 216 return $this->_TransHor3D($aGdImg,$aHorizon,$aSkewDist,$aDir,$aMinSize,$aFillColor,$aHiQuality,$aBorder); 217 218 } 219 220 220 } 221 221
Note:
See TracChangeset
for help on using the changeset viewer.