Witam,

Chciałbym poprawić cień (Linia 71) pod generowanym tekstem. Chciałbym aby był w postaci rozmycia w CSS wygląda on tak: text-shadow: 1px 1px 1px #000, 3px 3px 5px rgb(3, 3, 3);

Jak uzyskać taki sam efekt w poniższym skrypcie?

  1. <?php
  2.  
  3. function hex2rgb($hex) {
  4. $hex = str_replace("#", "", $hex);
  5.  
  6. if(strlen($hex) == 3) {
  7. $r = hexdec(substr($hex,0,1).substr($hex,0,1));
  8. $g = hexdec(substr($hex,1,1).substr($hex,1,1));
  9. $b = hexdec(substr($hex,2,1).substr($hex,2,1));
  10. } else {
  11. $r = hexdec(substr($hex,0,2));
  12. $g = hexdec(substr($hex,2,2));
  13. $b = hexdec(substr($hex,4,2));
  14. }
  15. $rgb = array($r, $g, $b);
  16. //return implode(",", $rgb); // returns the rgb values separated by commas
  17. return $rgb; // returns an array with the rgb values
  18. }
  19.  
  20. class QuoteImage {
  21. var $sourceImg;
  22. var $logoImg;
  23. var $outImg;
  24. var $targetWidth = 500;
  25. var $source_attr = array();
  26. var $font = 'fonts/gunplay.ttf';
  27. var $fontSize = 20;
  28. var $txt = array();
  29. var $colors = array();
  30. var $align;
  31. var $valign;
  32. var $image_name;
  33. var $transparentBG;
  34.  
  35. function __construct($image_name, $txt, $colors, $fontSize, $align, $valign, $transparentBG) {
  36. $this->image_name = $image_name;
  37. $this->transparentBG = $transparentBG;
  38.  
  39.  
  40. $ext = explode('.',$this->image_name);
  41. $ext = $ext[count($ext)-1];
  42.  
  43. $name = substr(md5(rand()), 0, 15);
  44.  
  45. switch($ext) {
  46. case 'jpeg':
  47. $this->sourceImg = imagecreatefromjpeg($image_name);
  48. $name .= '.jpg';
  49. break;
  50. case 'jpg':
  51. $this->sourceImg = imagecreatefromjpeg($image_name);
  52. $name .= '.jpg';
  53. break;
  54. case 'gif':
  55. $this->sourceImg = imagecreatefromgif($image_name);
  56. $name .= '.gif';
  57. break;
  58. case 'png':
  59. $this->sourceImg = imagecreatefrompng($image_name);
  60. $name .= '.png';
  61. break;
  62. }
  63.  
  64. $this->image_name = $name;
  65.  
  66. $this->logoImg = imagecreatefrompng(Q.'img/logo.png');
  67.  
  68. $colorBG = hex2rgb($colors['bg']);
  69. $colorText = hex2rgb($colors['text']);
  70.  
  71. $colors['bg'] = imagecolorallocate($this->sourceImg, $colorBG[0],$colorBG[1], $colorBG[2]);
  72. $colors['text'] = imagecolorallocate($this->sourceImg, $colorText[0], $colorText[1], $colorText[2]);
  73. $colors['shadow'] = imagecolorallocate($this->sourceImg, 51, 51, 51);
  74.  
  75. $this->source_attr = array('w' => imagesx($this->sourceImg), 'h' => imagesy($this->sourceImg));
  76. $this->txt = $txt;
  77. $this->font = Q.$this->font;
  78. $this->fontSize = $fontSize;
  79. $this->colors = $colors;
  80.  
  81. $this->align = $align;
  82. $this->valign = $valign;
  83. }
  84.  
  85. public function prepare() {
  86. $target_height = $this->source_attr['h'];
  87. if($this->targetWidth < $this->source_attr['w']) {
  88. $scale_ratio = $this->source_attr['w']/$this->targetWidth;
  89. $target_height = $this->source_attr['h']*$scale_ratio;
  90. }
  91.  
  92. //Create our basic image stream 300x300 pixels
  93. $this->outImg = imagecreatetruecolor($this->targetWidth , $target_height);
  94. //$this->tempImg = imagecreatetruecolor($this->targetWidth , $target_height);
  95.  
  96. $overlay = imagecreatefrompng(Q.'img/overlay.png');
  97.  
  98. imagecopyresampled($this->outImg, $this->sourceImg, 0,0,0,0,
  99. $this->targetWidth, $target_height,
  100. $this->source_attr['w'], $this->source_attr['h']);
  101.  
  102. imagecopyresampled($this->outImg, $overlay, 0,0,0,0,
  103. $this->targetWidth, $target_height,
  104. 1, 1);
  105.  
  106. }
  107.  
  108. public function alignTxt($line = 0, $align = 'center', $valign = 'middle') {
  109. $bbox = imagettfbbox($this->fontSize,0,$this->font,$this->txt[$line]);
  110.  
  111. switch($align) {
  112. case 'left':
  113. // align left
  114. $left = 18;
  115. break;
  116. // align right
  117. case 'right':
  118. $left = imagesx($this->outImg)-($bbox[4]+18);
  119. break;
  120. // align center
  121. case 'center':
  122. $left = $bbox[0] + (imagesx($this->outImg) / 2) - ($bbox[4] / 2);
  123. break;
  124. }
  125.  
  126. switch($valign) {
  127. case 'top':
  128. // align top
  129. $top = imagesy($this->logoImg);
  130. break;
  131. // align bottom
  132. case 'bottom':
  133. $margin = floor((count($this->txt)*($this->fontSize*1.33+13)))+imagesy($this->logoImg)-18;
  134. $top = imagesy($this->outImg)-($bbox[5]+$this->fontSize*1.33) - $margin;
  135. break;
  136. // align middle
  137. case 'middle':
  138. $margin = floor((count($this->txt)*($this->fontSize*1.33+13))+imagesy($this->logoImg)-10)/2;
  139. $top = $bbox[1] + (imagesy($this->outImg) / 2) - ($bbox[5] / 2) - $margin;
  140. break;
  141. }
  142.  
  143. $return = array('left' => $left, 'top' => $top, 'bbox' => $bbox);
  144. return $return;
  145. }
  146.  
  147. public function insertLogo($align = 'center', $valign = 'middle') {
  148. switch($align) {
  149. case 'left':
  150. // align left
  151. $left = 10;
  152. break;
  153. // align right
  154. case 'right':
  155. $left = imagesx($this->outImg)-(imagesx($this->logoImg)+10);
  156. break;
  157. // align center
  158. case 'center':
  159. $left = floor((imagesx($this->outImg)-imagesx($this->logoImg)) / 2);
  160. break;
  161. }
  162.  
  163. switch($valign) {
  164. case 'top':
  165. // align top
  166. $top = 10;
  167. break;
  168. // align bottom
  169. case 'bottom':
  170. $margin = floor((count($this->txt)*($this->fontSize*1.33+13)))+imagesy($this->logoImg)+28;
  171. $top = imagesy($this->outImg) - $margin;
  172. break;
  173. // align middle
  174. case 'middle':
  175. $margin = floor((count($this->txt)*($this->fontSize*1.33+13))+imagesy($this->logoImg)-10)/2;
  176. $top = floor((imagesy($this->outImg)-imagesy($this->logoImg)) / 2) - $margin;
  177. break;
  178. }
  179.  
  180. $return = array('left' => $left, 'top' => $top);
  181. return $return;
  182. }
  183.  
  184. public function output() {
  185. $margin = 0;
  186.  
  187. $logo = $this->insertLogo($this->align, $this->valign);
  188.  
  189. imagecopyresampled($this->outImg, $this->logoImg, $logo['left'],$logo['top'], 0,0,
  190. imagesx($this->logoImg), imagesy($this->logoImg),
  191. imagesx($this->logoImg), imagesy($this->logoImg));
  192.  
  193. $margin = imagesy($this->logoImg);
  194.  
  195. for($i=0;$i<count($this->txt);$i++) {
  196. $align = $this->alignTxt($i, $this->align, $this->valign);
  197.  
  198. if($i == 0) {
  199. $bg_positions = imagettftext($this->outImg, $this->fontSize, 0, $align['left'], $align['top']+ $margin, $this->colors['text'], $this->font, $this->txt[$i]);
  200. } else {
  201. $bg_positions = imagettftext($this->outImg, $this->fontSize, 0, $align['left'], $margin, $this->colors['text'], $this->font, $this->txt[$i]);
  202. }
  203.  
  204. $x = $bg_positions[0]-6;
  205. $x1 = $bg_positions[2]+6;
  206. $y = $bg_positions[5]-7;
  207. $y1 = $bg_positions[3]+7;
  208. //$y =
  209. if($this->transparentBG == "true") {
  210. imagefilledrectangle($this->outImg, $x, $y, $x1, $y1, $this->colors['bg']);
  211. }
  212.  
  213. if($i == 0) {
  214. if($this->transparentBG == "false") {
  215. imagettftext($this->outImg, $this->fontSize, 0, $align['left']+2, $align['top']+ $margin+2, $this->colors['shadow'], $this->font, $this->txt[$i]);
  216. }
  217. imagettftext($this->outImg, $this->fontSize, 0, $align['left'], $align['top']+ $margin, $this->colors['text'], $this->font, $this->txt[$i]);
  218. } else {
  219. if($this->transparentBG == "false") {
  220. imagettftext($this->outImg, $this->fontSize, 0, $align['left']+2, $margin+2, $this->colors['shadow'], $this->font, $this->txt[$i]);
  221. }
  222. imagettftext($this->outImg, $this->fontSize, 0, $align['left'], $margin, $this->colors['text'], $this->font, $this->txt[$i]);
  223. }
  224. //Set the content type
  225. $margin = ($y1+$this->fontSize+1);
  226. }
  227. //header('content-type: image/png');
  228.  
  229. imagepng($this->outImg, WP_CONTENT_DIR.'/uploads/cytaty/'.$this->image_name);
  230.  
  231. imagedestroy($this->outImg);
  232. }
  233. }
  234.  
  235. ?>