From ae605a1a5f01c24a56c1c1bc4797f45eddd330e3 Mon Sep 17 00:00:00 2001 From: Chouchen Date: Fri, 26 Nov 2010 15:07:16 +0000 Subject: [PATCH] =?UTF-8?q?Ajout=20de=20gd=5Finfo.php=20pour=20v=C3=A9rifi?= =?UTF-8?q?er=20si=20le=20serveur=20accepte=20cette=20classe.=20Ajout=20d'?= =?UTF-8?q?=C3=A9l=C3=A9ments=20SVG=20(stroke-width,=20text)=20Ajout=20d'?= =?UTF-8?q?=C3=A9l=C3=A9ments=20GD=20(allocate=20color)=20Modification=20d?= =?UTF-8?q?'elipse=20en=20arc=20(pour=20stroke-width...=20bug=20GD)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/gd_info.php | 2 ++ trunk/svgtoimage.php | 63 +++++++++++++++++++++++++++++++++++--------- trunk/test.php | 6 +++-- 3 files changed, 57 insertions(+), 14 deletions(-) create mode 100644 trunk/gd_info.php diff --git a/trunk/gd_info.php b/trunk/gd_info.php new file mode 100644 index 0000000..fa9f66a --- /dev/null +++ b/trunk/gd_info.php @@ -0,0 +1,2 @@ +_height) ? $this->_height : $this->_svgXML->attributes()->height; } - + private function _parseColor($colorCode){ if(strlen($colorCode) == 7){ if($this->_debug) $this->_log->message('Parse Color '.$colorCode); @@ -120,6 +126,11 @@ class SVGTOIMAGE{ return array(0,0,0); } + private function _allocateColor($color){ + $arrayColor = $this->_parseColor($color); + return imagecolorallocate( $this->_image, $arrayColor[0], $arrayColor[1], $arrayColor[2] ); + } + private function _parseImage($imageNode){ $x = 0; $y = 0; @@ -172,10 +183,17 @@ class SVGTOIMAGE{ imagecopy($this->_image,$newImage,$x,$y,0,0,imagesx($newImage) , imagesy($newImage)); } + private function _parsePath($pathNode){ + // tODO with imageline ( resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color ) + // imagesetbrush + // imagesetstyle (pour dotted, dashed etc) + } + private function _parseCircle($circleNode){ $x = 0; $y = 0; $r = 0; + $strokeWidth = 1; $fill = ''; $stroke = ''; foreach($circleNode->attributes() as $name => $value){ @@ -187,20 +205,29 @@ class SVGTOIMAGE{ case 'fill': $fill = ($value == 'none') ? '' : $value; break; case 'stroke': $stroke = $value; break; case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; + case 'stroke-width' : $strokeWidth = $value; break; } } if($r == 0) return; - $colorStroke = $this->_parseColor($stroke); - $colorFill = $this->_parseColor($fill); - if($this->_debug) $this->_log->message('Cercle - x : '.$x.' - y : '.$y.' - rayon : '.$r.' - fill : '.$colorFill[0].'-'.$colorFill[1].'-'.$colorFill[2].' - stroke : '.$colorStroke[0].'-'.$colorStroke[1].'-'.$colorStroke[2]); - if($fill == ''){ + if($this->_debug) $this->_log->message('Cercle - x : '.$x.' - y : '.$y.' - rayon : '.$r.'-'.$colorStroke[2].' - épaisseur : '.$strokeWidth); + + $thickness = imagesetthickness( $this->_image , (int)$strokeWidth ); + if($this->_debug && !$thickness) $this->_log->error('Erreur dans la mise en place de l\'épaisseur du trait'); - imageellipse ($this->_image , $x , $y , $r*2 , $r*2, imagecolorallocate($this->_image, $colorStroke[0], $colorStroke[1], $colorStroke[2]) ); + $colorStroke = $this->_allocateColor($stroke); + $colorFill = $this->_allocateColor($fill); + + if($fill == ''){ + imagearc($this->_image , $x , $y , $r*2 , $r*2,0,359.9, $colorStroke ); + //imageellipse ($this->_image , $x , $y , $r*2 , $r*2, $colorStroke ); }else{ - imagefilledellipse($this->_image , $x , $y , $r*2 , $r*2 , imagecolorallocate($this->_image, $colorFill[0], $colorFill[1], $colorFill[2]) ); + imagefilledarc($this->_image , $x , $y , $r*2 , $r*2 ,0,359.9, $colorFill, IMG_ARC_PIE ); } + imagecolordeallocate( $this->_image, $colorStroke); + imagecolordeallocate( $this->_image, $colorFill); + imagesetthickness ( $this->_image , 1 ); } private function _parseRectangle($rectNode){ @@ -212,9 +239,11 @@ class SVGTOIMAGE{ $r = 0; $fill = ''; $stroke = ''; + $strokeWidth = 1; foreach($rectNode->attributes() as $name => $value){ switch($name){ - //TODO style display:none + // imagesetthickness ( resource $image , int $thickness ) + // imagesetstyle (pour dotted, dashed etc) case 'x': $x = $value; break; case 'y': $y = $value; break; case 'r': $r = $value; break; @@ -222,19 +251,25 @@ class SVGTOIMAGE{ case 'height': $height = $value; break; case 'fill': $fill = ($value == 'none') ? '' : $value; break; case 'stroke': $stroke = $value; break; + case 'stroke-width' : $strokeWidth = $value; break; case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break; } } if($width == 0 || $height == 0) return; - $colorStroke = $this->_parseColor($stroke); - $colorFill = $this->_parseColor($fill); + $colorStroke = $this->_allocateColor($stroke); + $colorFill = $this->_allocateColor($fill); + $thickness = imagesetthickness( $this->_image , (int)$strokeWidth ); + if($this->_debug && !$thickness) $this->_log->error('Erreur dans la mise en place de l\'épaisseur du trait'); if($this->_debug) $this->_log->message('Rectangle - x : '.$x.' - y : '.$y.' - width : '.$width.' - height : '.$height.' - fill : '.$colorFill[0].'-'.$colorFill[1].'-'.$colorFill[2].' - stroke : '.$colorStroke[0].'-'.$colorStroke[1].'-'.$colorStroke[2]); if($fill == ''){ - imagerectangle($this->_image , $x , $y , $x+$width , $y+$height, imagecolorallocate($this->_image, $colorStroke[0], $colorStroke[1], $colorStroke[2]) ); //resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color + imagerectangle($this->_image , $x , $y , $x+$width , $y+$height, $colorStroke); //resource $image , int $x1 , int $y1 , int $x2 , int $y2 , int $color }else{ - imagefilledrectangle ($this->_image , $x , $y , $x+$width , $y+$height, imagecolorallocate($this->_image, $colorFill[0], $colorFill[1], $colorFill[2]) ); + imagefilledrectangle ($this->_image , $x , $y , $x+$width , $y+$height, $colorFill ); } + imagecolordeallocate($this->_image,$colorStroke); + imagecolordeallocate($this->_image,$colorFill); + imagesetthickness ( $this->_image , 1 ); } private function _parseDescription($desc){ @@ -243,8 +278,11 @@ class SVGTOIMAGE{ } public function toImage(){ + //$test = Imagick::__construct('http://labs.shikiryu.com/experimental-cut/images/pieces/2.png'); $writeDesc = null; $this->_image = imagecreatetruecolor($this->_getImageWidth(), $this->_getImageHeight()); + imagealphablending($this->_image, true); + imageantialias($this->_image, true); foreach($this->_svgXML->children() as $element){ if($element->getName() == 'image') $this->_parseImage($element); @@ -256,6 +294,7 @@ class SVGTOIMAGE{ $writeDesc = $element; } if($writeDesc) $this->_parseDescription($writeDesc); + //imagefilter ( $this->_image , IMG_FILTER_SMOOTH, 6); return imagepng($this->_image); } diff --git a/trunk/test.php b/trunk/test.php index 666ba0b..ac8bc2f 100644 --- a/trunk/test.php +++ b/trunk/test.php @@ -8,13 +8,15 @@ $svg = 'Created with Raphael - + + '; +$svgtoimage = SVGTOIMAGE::parse($svg); //$svgtoimage = new SVGTOIMAGE($svg); -$svgtoimage = SVGTOIMAGE::load('basic.svg'); +//$svgtoimage = SVGTOIMAGE::load('basic.svg'); $svgtoimage->setShowDesc(); $svgtoimage->setWidth(300); $svgtoimage->setHeight(512);