mirror of
https://github.com/Chouchen/svgToImage.git
synced 2020-02-03 22:08:42 +01:00
Ajout de l'header dans la classe et de 2 formats de sortie
This commit is contained in:
parent
dd7e4a4ba4
commit
1bb11ac336
@ -1,8 +1,6 @@
|
|||||||
<?
|
<?
|
||||||
// TODO
|
// TODO
|
||||||
// ajouter header thanks to http://fr.php.net/manual/fr/function.image-type-to-mime-type.php
|
|
||||||
// prendre en compte l'opacité grâce à imagecolorallocatealpha ?
|
// prendre en compte l'opacité grâce à imagecolorallocatealpha ?
|
||||||
// stroke-width pour tous \o/
|
|
||||||
// pour les rectangles avec point ou tiret http://fr.php.net/manual/fr/function.imagesetstyle.php
|
// pour les rectangles avec point ou tiret http://fr.php.net/manual/fr/function.imagesetstyle.php
|
||||||
// ajout de title
|
// ajout de title
|
||||||
|
|
||||||
@ -20,7 +18,7 @@ class SVGTOIMAGE{
|
|||||||
protected $_showDesc = false;
|
protected $_showDesc = false;
|
||||||
protected $_desc;
|
protected $_desc;
|
||||||
private $transparentColor = array(0,0,255);
|
private $transparentColor = array(0,0,255);
|
||||||
public $_debug = true;
|
public $_debug = true; // change to false to stop debug mode
|
||||||
|
|
||||||
/* array of color names => hex color
|
/* array of color names => hex color
|
||||||
because some svg creator uses them
|
because some svg creator uses them
|
||||||
@ -231,7 +229,7 @@ class SVGTOIMAGE{
|
|||||||
case 'height': $height = $value; break;
|
case 'height': $height = $value; break;
|
||||||
case 'href':
|
case 'href':
|
||||||
case 'xlink:href':$href = $value; break;
|
case 'xlink:href':$href = $value; break;
|
||||||
//case 'r' : $r = $value; break; // no !
|
//case 'r' : $r = $value; break; // no, use transform instead !
|
||||||
case 'transform': $transform = $value;
|
case 'transform': $transform = $value;
|
||||||
case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break;
|
case 'style' : if(strripos($value, 'display: none') || strripos($value, 'display:none')) return; break;
|
||||||
}
|
}
|
||||||
@ -279,13 +277,13 @@ class SVGTOIMAGE{
|
|||||||
}
|
}
|
||||||
$newWidth = imagesx($newImage);
|
$newWidth = imagesx($newImage);
|
||||||
$newHeight = imagesy($newImage);
|
$newHeight = imagesy($newImage);
|
||||||
//imagecopy($this->_image,$newImage,$x,$y,0,0, $width , $height);
|
|
||||||
imagecopy($this->_image,$newImage,($newWidth == $width) ? $x : $x-($newWidth-$width)/2,($newHeight == $height) ? $y : $y-($newHeight-$height)/2,0,0,imagesx($newImage) , imagesy($newImage));
|
imagecopy($this->_image,$newImage,($newWidth == $width) ? $x : $x-($newWidth-$width)/2,($newHeight == $height) ? $y : $y-($newHeight-$height)/2,0,0,imagesx($newImage) , imagesy($newImage)); // Thanks Raphael & GD for saying things wrong.
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the given SVG xml is W3C valid
|
* Check if the given SVG xml is W3C valid
|
||||||
* DEPRECATED
|
* DEPRECATED and unused anymore
|
||||||
* @param string <svg>...</svg>
|
* @param string <svg>...</svg>
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
@ -665,9 +663,15 @@ class SVGTOIMAGE{
|
|||||||
if($this->_showDesc && $this->_desc != null) $this->_parseDescription($this->_desc);
|
if($this->_showDesc && $this->_desc != null) $this->_parseDescription($this->_desc);
|
||||||
//imagefilter ( $this->_image , IMG_FILTER_SMOOTH, 6);
|
//imagefilter ( $this->_image , IMG_FILTER_SMOOTH, 6);
|
||||||
switch($format){
|
switch($format){
|
||||||
|
case 'gif' :
|
||||||
|
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_GIF));
|
||||||
|
return imagegif($this->_image, $path);
|
||||||
|
case 'jpg':
|
||||||
|
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_JPEG));
|
||||||
|
return imagejpeg($this->_image, $path);
|
||||||
case 'png' :
|
case 'png' :
|
||||||
default :
|
default :
|
||||||
//header('Content-type: image/png');
|
header("Content-type: " . image_type_to_mime_type(IMAGETYPE_PNG));
|
||||||
return imagepng($this->_image, $path);
|
return imagepng($this->_image, $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
test.php
2
test.php
@ -39,5 +39,5 @@ $svgtoimage = SVGTOIMAGE::parse($svg);
|
|||||||
$svgtoimage->setShowDesc();
|
$svgtoimage->setShowDesc();
|
||||||
$svgtoimage->setWidth(300);
|
$svgtoimage->setWidth(300);
|
||||||
$svgtoimage->setHeight(512);
|
$svgtoimage->setHeight(512);
|
||||||
header('Content-type: image/png');
|
//header('Content-type: image/png');
|
||||||
echo $svgtoimage->toImage();
|
echo $svgtoimage->toImage();
|
Loading…
x
Reference in New Issue
Block a user