gd_adapter.cls.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. <?php
  2. /**
  3. * @package dompdf
  4. * @link http://dompdf.github.com/
  5. * @author Benj Carson <benjcarson@digitaljunkies.ca>
  6. * @author Fabien Ménager <fabien.menager@gmail.com>
  7. * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
  8. */
  9. /**
  10. * Image rendering interface
  11. *
  12. * Renders to an image format supported by GD (jpeg, gif, png, xpm).
  13. * Not super-useful day-to-day but handy nonetheless
  14. *
  15. * @package dompdf
  16. */
  17. class GD_Adapter implements Canvas {
  18. /**
  19. * @var DOMPDF
  20. */
  21. private $_dompdf;
  22. /**
  23. * Resource handle for the image
  24. *
  25. * @var resource
  26. */
  27. private $_img;
  28. /**
  29. * Image width in pixels
  30. *
  31. * @var int
  32. */
  33. private $_width;
  34. /**
  35. * Image height in pixels
  36. *
  37. * @var int
  38. */
  39. private $_height;
  40. /**
  41. * Current page number
  42. *
  43. * @var int
  44. */
  45. private $_page_number;
  46. /**
  47. * Total number of pages
  48. *
  49. * @var int
  50. */
  51. private $_page_count;
  52. /**
  53. * Image antialias factor
  54. *
  55. * @var float
  56. */
  57. private $_aa_factor;
  58. /**
  59. * Allocated colors
  60. *
  61. * @var array
  62. */
  63. private $_colors;
  64. /**
  65. * Background color
  66. *
  67. * @var int
  68. */
  69. private $_bg_color;
  70. /**
  71. * Class constructor
  72. *
  73. * @param mixed $size The size of image to create: array(x1,y1,x2,y2) or "letter", "legal", etc.
  74. * @param string $orientation The orientation of the document (either 'landscape' or 'portrait')
  75. * @param DOMPDF $dompdf
  76. * @param float $aa_factor Anti-aliasing factor, 1 for no AA
  77. * @param array $bg_color Image background color: array(r,g,b,a), 0 <= r,g,b,a <= 1
  78. */
  79. function __construct($size, $orientation = "portrait", DOMPDF $dompdf, $aa_factor = 1.0, $bg_color = array(1,1,1,0) ) {
  80. if ( !is_array($size) ) {
  81. $size = strtolower($size);
  82. if ( isset(CPDF_Adapter::$PAPER_SIZES[$size]) ) {
  83. $size = CPDF_Adapter::$PAPER_SIZES[$size];
  84. }
  85. else {
  86. $size = CPDF_Adapter::$PAPER_SIZES["letter"];
  87. }
  88. }
  89. if ( strtolower($orientation) === "landscape" ) {
  90. list($size[2],$size[3]) = array($size[3],$size[2]);
  91. }
  92. $this->_dompdf = $dompdf;
  93. if ( $aa_factor < 1 ) {
  94. $aa_factor = 1;
  95. }
  96. $this->_aa_factor = $aa_factor;
  97. $size[2] *= $aa_factor;
  98. $size[3] *= $aa_factor;
  99. $this->_width = $size[2] - $size[0];
  100. $this->_height = $size[3] - $size[1];
  101. $this->_img = imagecreatetruecolor($this->_width, $this->_height);
  102. if ( is_null($bg_color) || !is_array($bg_color) ) {
  103. // Pure white bg
  104. $bg_color = array(1,1,1,0);
  105. }
  106. $this->_bg_color = $this->_allocate_color($bg_color);
  107. imagealphablending($this->_img, true);
  108. imagesavealpha($this->_img, true);
  109. imagefill($this->_img, 0, 0, $this->_bg_color);
  110. }
  111. function get_dompdf(){
  112. return $this->_dompdf;
  113. }
  114. /**
  115. * Return the GF image resource
  116. *
  117. * @return resource
  118. */
  119. function get_image() { return $this->_img; }
  120. /**
  121. * Return the image's width in pixels
  122. *
  123. * @return float
  124. */
  125. function get_width() { return $this->_width / $this->_aa_factor; }
  126. /**
  127. * Return the image's height in pixels
  128. *
  129. * @return float
  130. */
  131. function get_height() { return $this->_height / $this->_aa_factor; }
  132. /**
  133. * Returns the current page number
  134. * @return int
  135. */
  136. function get_page_number() { return $this->_page_number; }
  137. /**
  138. * Returns the total number of pages in the document
  139. * @return int
  140. */
  141. function get_page_count() { return $this->_page_count; }
  142. /**
  143. * Sets the current page number
  144. *
  145. * @param int $num
  146. */
  147. function set_page_number($num) { $this->_page_number = $num; }
  148. /**
  149. * Sets the page count
  150. *
  151. * @param int $count
  152. */
  153. function set_page_count($count) { $this->_page_count = $count; }
  154. /**
  155. * Sets the opacity
  156. *
  157. * @param $opacity
  158. * @param $mode
  159. */
  160. function set_opacity($opacity, $mode = "Normal") {
  161. // FIXME
  162. }
  163. /**
  164. * Allocate a new color. Allocate with GD as needed and store
  165. * previously allocated colors in $this->_colors.
  166. *
  167. * @param array $color The new current color
  168. * @return int The allocated color
  169. */
  170. private function _allocate_color($color) {
  171. if ( isset($color["c"]) ) {
  172. $color = cmyk_to_rgb($color);
  173. }
  174. // Full opacity if no alpha set
  175. if ( !isset($color[3]) )
  176. $color[3] = 0;
  177. list($r,$g,$b,$a) = $color;
  178. $r *= 255;
  179. $g *= 255;
  180. $b *= 255;
  181. $a *= 127;
  182. // Clip values
  183. $r = $r > 255 ? 255 : $r;
  184. $g = $g > 255 ? 255 : $g;
  185. $b = $b > 255 ? 255 : $b;
  186. $a = $a > 127 ? 127 : $a;
  187. $r = $r < 0 ? 0 : $r;
  188. $g = $g < 0 ? 0 : $g;
  189. $b = $b < 0 ? 0 : $b;
  190. $a = $a < 0 ? 0 : $a;
  191. $key = sprintf("#%02X%02X%02X%02X", $r, $g, $b, $a);
  192. if ( isset($this->_colors[$key]) )
  193. return $this->_colors[$key];
  194. if ( $a != 0 )
  195. $this->_colors[$key] = imagecolorallocatealpha($this->_img, $r, $g, $b, $a);
  196. else
  197. $this->_colors[$key] = imagecolorallocate($this->_img, $r, $g, $b);
  198. return $this->_colors[$key];
  199. }
  200. /**
  201. * Draws a line from x1,y1 to x2,y2
  202. *
  203. * See {@link Style::munge_color()} for the format of the color array.
  204. * See {@link Cpdf::setLineStyle()} for a description of the format of the
  205. * $style parameter (aka dash).
  206. *
  207. * @param float $x1
  208. * @param float $y1
  209. * @param float $x2
  210. * @param float $y2
  211. * @param array $color
  212. * @param float $width
  213. * @param array $style
  214. */
  215. function line($x1, $y1, $x2, $y2, $color, $width, $style = null) {
  216. // Scale by the AA factor
  217. $x1 *= $this->_aa_factor;
  218. $y1 *= $this->_aa_factor;
  219. $x2 *= $this->_aa_factor;
  220. $y2 *= $this->_aa_factor;
  221. $width *= $this->_aa_factor;
  222. $c = $this->_allocate_color($color);
  223. // Convert the style array if required
  224. if ( !is_null($style) ) {
  225. $gd_style = array();
  226. if ( count($style) == 1 ) {
  227. for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
  228. $gd_style[] = $c;
  229. }
  230. for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++) {
  231. $gd_style[] = $this->_bg_color;
  232. }
  233. } else {
  234. $i = 0;
  235. foreach ($style as $length) {
  236. if ( $i % 2 == 0 ) {
  237. // 'On' pattern
  238. for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++)
  239. $gd_style[] = $c;
  240. } else {
  241. // Off pattern
  242. for ($i = 0; $i < $style[0] * $this->_aa_factor; $i++)
  243. $gd_style[] = $this->_bg_color;
  244. }
  245. $i++;
  246. }
  247. }
  248. imagesetstyle($this->_img, $gd_style);
  249. $c = IMG_COLOR_STYLED;
  250. }
  251. imagesetthickness($this->_img, $width);
  252. imageline($this->_img, $x1, $y1, $x2, $y2, $c);
  253. }
  254. function arc($x1, $y1, $r1, $r2, $astart, $aend, $color, $width, $style = array()) {
  255. // @todo
  256. }
  257. /**
  258. * Draws a rectangle at x1,y1 with width w and height h
  259. *
  260. * See {@link Style::munge_color()} for the format of the color array.
  261. * See {@link Cpdf::setLineStyle()} for a description of the $style
  262. * parameter (aka dash)
  263. *
  264. * @param float $x1
  265. * @param float $y1
  266. * @param float $w
  267. * @param float $h
  268. * @param array $color
  269. * @param float $width
  270. * @param array $style
  271. */
  272. function rectangle($x1, $y1, $w, $h, $color, $width, $style = null) {
  273. // Scale by the AA factor
  274. $x1 *= $this->_aa_factor;
  275. $y1 *= $this->_aa_factor;
  276. $w *= $this->_aa_factor;
  277. $h *= $this->_aa_factor;
  278. $c = $this->_allocate_color($color);
  279. // Convert the style array if required
  280. if ( !is_null($style) ) {
  281. $gd_style = array();
  282. foreach ($style as $length) {
  283. for ($i = 0; $i < $length; $i++) {
  284. $gd_style[] = $c;
  285. }
  286. }
  287. imagesetstyle($this->_img, $gd_style);
  288. $c = IMG_COLOR_STYLED;
  289. }
  290. imagesetthickness($this->_img, $width);
  291. imagerectangle($this->_img, $x1, $y1, $x1 + $w, $y1 + $h, $c);
  292. }
  293. /**
  294. * Draws a filled rectangle at x1,y1 with width w and height h
  295. *
  296. * See {@link Style::munge_color()} for the format of the color array.
  297. *
  298. * @param float $x1
  299. * @param float $y1
  300. * @param float $w
  301. * @param float $h
  302. * @param array $color
  303. */
  304. function filled_rectangle($x1, $y1, $w, $h, $color) {
  305. // Scale by the AA factor
  306. $x1 *= $this->_aa_factor;
  307. $y1 *= $this->_aa_factor;
  308. $w *= $this->_aa_factor;
  309. $h *= $this->_aa_factor;
  310. $c = $this->_allocate_color($color);
  311. imagefilledrectangle($this->_img, $x1, $y1, $x1 + $w, $y1 + $h, $c);
  312. }
  313. /**
  314. * Starts a clipping rectangle at x1,y1 with width w and height h
  315. *
  316. * @param float $x1
  317. * @param float $y1
  318. * @param float $w
  319. * @param float $h
  320. */
  321. function clipping_rectangle($x1, $y1, $w, $h) {
  322. // @todo
  323. }
  324. function clipping_roundrectangle($x1, $y1, $w, $h, $rTL, $rTR, $rBR, $rBL) {
  325. // @todo
  326. }
  327. /**
  328. * Ends the last clipping shape
  329. */
  330. function clipping_end() {
  331. // @todo
  332. }
  333. function save() {
  334. // @todo
  335. }
  336. function restore() {
  337. // @todo
  338. }
  339. function rotate($angle, $x, $y) {
  340. // @todo
  341. }
  342. function skew($angle_x, $angle_y, $x, $y) {
  343. // @todo
  344. }
  345. function scale($s_x, $s_y, $x, $y) {
  346. // @todo
  347. }
  348. function translate($t_x, $t_y) {
  349. // @todo
  350. }
  351. function transform($a, $b, $c, $d, $e, $f) {
  352. // @todo
  353. }
  354. /**
  355. * Draws a polygon
  356. *
  357. * The polygon is formed by joining all the points stored in the $points
  358. * array. $points has the following structure:
  359. * <code>
  360. * array(0 => x1,
  361. * 1 => y1,
  362. * 2 => x2,
  363. * 3 => y2,
  364. * ...
  365. * );
  366. * </code>
  367. *
  368. * See {@link Style::munge_color()} for the format of the color array.
  369. * See {@link Cpdf::setLineStyle()} for a description of the $style
  370. * parameter (aka dash)
  371. *
  372. * @param array $points
  373. * @param array $color
  374. * @param float $width
  375. * @param array $style
  376. * @param bool $fill Fills the polygon if true
  377. */
  378. function polygon($points, $color, $width = null, $style = null, $fill = false) {
  379. // Scale each point by the AA factor
  380. foreach (array_keys($points) as $i)
  381. $points[$i] *= $this->_aa_factor;
  382. $c = $this->_allocate_color($color);
  383. // Convert the style array if required
  384. if ( !is_null($style) && !$fill ) {
  385. $gd_style = array();
  386. foreach ($style as $length) {
  387. for ($i = 0; $i < $length; $i++) {
  388. $gd_style[] = $c;
  389. }
  390. }
  391. imagesetstyle($this->_img, $gd_style);
  392. $c = IMG_COLOR_STYLED;
  393. }
  394. imagesetthickness($this->_img, $width);
  395. if ( $fill )
  396. imagefilledpolygon($this->_img, $points, count($points) / 2, $c);
  397. else
  398. imagepolygon($this->_img, $points, count($points) / 2, $c);
  399. }
  400. /**
  401. * Draws a circle at $x,$y with radius $r
  402. *
  403. * See {@link Style::munge_color()} for the format of the color array.
  404. * See {@link Cpdf::setLineStyle()} for a description of the $style
  405. * parameter (aka dash)
  406. *
  407. * @param float $x
  408. * @param float $y
  409. * @param float $r
  410. * @param array $color
  411. * @param float $width
  412. * @param array $style
  413. * @param bool $fill Fills the circle if true
  414. */
  415. function circle($x, $y, $r, $color, $width = null, $style = null, $fill = false) {
  416. // Scale by the AA factor
  417. $x *= $this->_aa_factor;
  418. $y *= $this->_aa_factor;
  419. $r *= $this->_aa_factor;
  420. $c = $this->_allocate_color($color);
  421. // Convert the style array if required
  422. if ( !is_null($style) && !$fill ) {
  423. $gd_style = array();
  424. foreach ($style as $length) {
  425. for ($i = 0; $i < $length; $i++) {
  426. $gd_style[] = $c;
  427. }
  428. }
  429. imagesetstyle($this->_img, $gd_style);
  430. $c = IMG_COLOR_STYLED;
  431. }
  432. imagesetthickness($this->_img, $width);
  433. if ( $fill )
  434. imagefilledellipse($this->_img, $x, $y, $r, $r, $c);
  435. else
  436. imageellipse($this->_img, $x, $y, $r, $r, $c);
  437. }
  438. /**
  439. * Add an image to the pdf.
  440. * The image is placed at the specified x and y coordinates with the
  441. * given width and height.
  442. *
  443. * @param string $img_url the path to the image
  444. * @param float $x x position
  445. * @param float $y y position
  446. * @param int $w width (in pixels)
  447. * @param int $h height (in pixels)
  448. * @param string $resolution
  449. *
  450. * @return void
  451. * @internal param string $img_type the type (e.g. extension) of the image
  452. */
  453. function image($img_url, $x, $y, $w, $h, $resolution = "normal") {
  454. $img_type = Image_Cache::detect_type($img_url);
  455. $img_ext = Image_Cache::type_to_ext($img_type);
  456. if ( !$img_ext ) {
  457. return;
  458. }
  459. $func = "imagecreatefrom$img_ext";
  460. $src = @$func($img_url);
  461. if ( !$src ) {
  462. return; // Probably should add to $_dompdf_errors or whatever here
  463. }
  464. // Scale by the AA factor
  465. $x *= $this->_aa_factor;
  466. $y *= $this->_aa_factor;
  467. $w *= $this->_aa_factor;
  468. $h *= $this->_aa_factor;
  469. $img_w = imagesx($src);
  470. $img_h = imagesy($src);
  471. imagecopyresampled($this->_img, $src, $x, $y, 0, 0, $w, $h, $img_w, $img_h);
  472. }
  473. /**
  474. * Writes text at the specified x and y coordinates
  475. * See {@link Style::munge_color()} for the format of the color array.
  476. *
  477. * @param float $x
  478. * @param float $y
  479. * @param string $text the text to write
  480. * @param string $font the font file to use
  481. * @param float $size the font size, in points
  482. * @param array $color
  483. * @param float $word_spacing word spacing adjustment
  484. * @param float $char_spacing
  485. * @param float $angle Text angle
  486. *
  487. * @return void
  488. */
  489. function text($x, $y, $text, $font, $size, $color = array(0,0,0), $word_spacing = 0.0, $char_spacing = 0.0, $angle = 0.0) {
  490. // Scale by the AA factor
  491. $x *= $this->_aa_factor;
  492. $y *= $this->_aa_factor;
  493. $size *= $this->_aa_factor;
  494. $h = $this->get_font_height($font, $size);
  495. $c = $this->_allocate_color($color);
  496. $text = mb_encode_numericentity($text, array(0x0080, 0xff, 0, 0xff), 'UTF-8');
  497. $font = $this->get_ttf_file($font);
  498. // FIXME: word spacing
  499. @imagettftext($this->_img, $size, $angle, $x, $y + $h, $c, $font, $text);
  500. }
  501. function javascript($code) {
  502. // Not implemented
  503. }
  504. /**
  505. * Add a named destination (similar to <a name="foo">...</a> in html)
  506. *
  507. * @param string $anchorname The name of the named destination
  508. */
  509. function add_named_dest($anchorname) {
  510. // Not implemented
  511. }
  512. /**
  513. * Add a link to the pdf
  514. *
  515. * @param string $url The url to link to
  516. * @param float $x The x position of the link
  517. * @param float $y The y position of the link
  518. * @param float $width The width of the link
  519. * @param float $height The height of the link
  520. */
  521. function add_link($url, $x, $y, $width, $height) {
  522. // Not implemented
  523. }
  524. /**
  525. * Add meta information to the PDF
  526. *
  527. * @param string $label label of the value (Creator, Producer, etc.)
  528. * @param string $value the text to set
  529. */
  530. function add_info($label, $value) {
  531. // N/A
  532. }
  533. function set_default_view($view, $options = array()) {
  534. // N/A
  535. }
  536. /**
  537. * Calculates text size, in points
  538. *
  539. * @param string $text the text to be sized
  540. * @param string $font the desired font
  541. * @param float $size the desired font size
  542. * @param float $word_spacing word spacing, if any
  543. * @param float $char_spacing char spacing, if any
  544. *
  545. * @return float
  546. */
  547. function get_text_width($text, $font, $size, $word_spacing = 0.0, $char_spacing = 0.0) {
  548. $font = $this->get_ttf_file($font);
  549. $text = mb_encode_numericentity($text, array(0x0080, 0xffff, 0, 0xffff), 'UTF-8');
  550. // FIXME: word spacing
  551. list($x1,,$x2) = @imagettfbbox($size, 0, $font, $text);
  552. return $x2 - $x1;
  553. }
  554. function get_ttf_file($font) {
  555. if ( strpos($font, '.ttf') === false )
  556. $font .= ".ttf";
  557. /*$filename = substr(strtolower(basename($font)), 0, -4);
  558. if ( in_array($filename, DOMPDF::$native_fonts) ) {
  559. return "arial.ttf";
  560. }*/
  561. return $font;
  562. }
  563. /**
  564. * Calculates font height, in points
  565. *
  566. * @param string $font
  567. * @param float $size
  568. * @return float
  569. */
  570. function get_font_height($font, $size) {
  571. $font = $this->get_ttf_file($font);
  572. $ratio = $this->_dompdf->get_option("font_height_ratio");
  573. // FIXME: word spacing
  574. list(,$y2,,,,$y1) = imagettfbbox($size, 0, $font, "MXjpqytfhl"); // Test string with ascenders, descenders and caps
  575. return ($y2 - $y1) * $ratio;
  576. }
  577. function get_font_baseline($font, $size) {
  578. $ratio = $this->_dompdf->get_option("font_height_ratio");
  579. return $this->get_font_height($font, $size) / $ratio;
  580. }
  581. /**
  582. * Starts a new page
  583. *
  584. * Subsequent drawing operations will appear on the new page.
  585. */
  586. function new_page() {
  587. $this->_page_number++;
  588. $this->_page_count++;
  589. }
  590. function open_object(){
  591. // N/A
  592. }
  593. function close_object(){
  594. // N/A
  595. }
  596. function add_object(){
  597. // N/A
  598. }
  599. function page_text(){
  600. // N/A
  601. }
  602. /**
  603. * Streams the image directly to the browser
  604. *
  605. * @param string $filename the name of the image file (ignored)
  606. * @param array $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)
  607. */
  608. function stream($filename, $options = null) {
  609. // Perform any antialiasing
  610. if ( $this->_aa_factor != 1 ) {
  611. $dst_w = $this->_width / $this->_aa_factor;
  612. $dst_h = $this->_height / $this->_aa_factor;
  613. $dst = imagecreatetruecolor($dst_w, $dst_h);
  614. imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,
  615. $dst_w, $dst_h,
  616. $this->_width, $this->_height);
  617. } else {
  618. $dst = $this->_img;
  619. }
  620. if ( !isset($options["type"]) )
  621. $options["type"] = "png";
  622. $type = strtolower($options["type"]);
  623. header("Cache-Control: private");
  624. switch ($type) {
  625. case "jpg":
  626. case "jpeg":
  627. if ( !isset($options["quality"]) )
  628. $options["quality"] = 75;
  629. header("Content-type: image/jpeg");
  630. imagejpeg($dst, '', $options["quality"]);
  631. break;
  632. case "png":
  633. default:
  634. header("Content-type: image/png");
  635. imagepng($dst);
  636. break;
  637. }
  638. if ( $this->_aa_factor != 1 )
  639. imagedestroy($dst);
  640. }
  641. /**
  642. * Returns the PNG as a string
  643. *
  644. * @param array $options associative array, 'type' => jpeg|jpg|png, 'quality' => 0 - 100 (jpeg only)
  645. * @return string
  646. */
  647. function output($options = null) {
  648. if ( $this->_aa_factor != 1 ) {
  649. $dst_w = $this->_width / $this->_aa_factor;
  650. $dst_h = $this->_height / $this->_aa_factor;
  651. $dst = imagecreatetruecolor($dst_w, $dst_h);
  652. imagecopyresampled($dst, $this->_img, 0, 0, 0, 0,
  653. $dst_w, $dst_h,
  654. $this->_width, $this->_height);
  655. } else {
  656. $dst = $this->_img;
  657. }
  658. if ( !isset($options["type"]) )
  659. $options["type"] = "png";
  660. $type = $options["type"];
  661. ob_start();
  662. switch ($type) {
  663. case "jpg":
  664. case "jpeg":
  665. if ( !isset($options["quality"]) )
  666. $options["quality"] = 75;
  667. imagejpeg($dst, '', $options["quality"]);
  668. break;
  669. case "png":
  670. default:
  671. imagepng($dst);
  672. break;
  673. }
  674. $image = ob_get_clean();
  675. if ( $this->_aa_factor != 1 )
  676. imagedestroy($dst);
  677. return $image;
  678. }
  679. }