Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Znak wodny na obrazku.
Forum PHP.pl > Forum > PHP
Recik
Witam. Znalazłem skrypt, który generuje znak wodny jednak w postaci tekstu a nie obrazka. Chciałbym jednak zrobić tak, aby generował się obrazek jako znak wodny. Poniżej kod:

  1. public function add() {
  2. App::import('Sanitize');
  3. $this->pageTitle .= ' - Dodaj';
  4. if($this->data) {
  5. $u = $this->Upload;
  6. $s = $this->Session;
  7. if(isset($this->data['Post']['cancel1'])) {
  8. @unlink(WWW_ROOT.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg');
  9. $this->Post->id =(int) $s->read('id');
  10. $this->Post->delete();
  11. $s->delete('step2');
  12. $s->delete('id');
  13. $s->delete('img');
  14. $s->delete('hash');
  15. $this->redirect($this->referer());
  16. }
  17. if(isset($this->data['Post']['cancel2'])) {
  18. @unlink(WWW_ROOT.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg');
  19. $s->del('step2');
  20. return;
  21. }
  22. if((int)$s->read('Auth.User.active')===2) {
  23. $s->setFlash('Twoje konto jest nieaktywne, potwierdź adres email.');
  24. $this->redirect($this->referer());
  25. }
  26.  
  27. $tag = trim($this->data['Post']['tag']);
  28. (!empty($tag)) ? $tag = explode(' ',$tag): $tag = null;
  29.  
  30. if(!$s->check('step2')) {
  31. if(!$s->check('img')) {
  32. $u->upload($this->data['Post']['img']);
  33. } else {
  34. $u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg');
  35. }
  36. if($u->uploaded) {
  37. if($s->check('img')) {
  38. $now = $s->read('img');
  39. } else {
  40. $now = time();
  41. }
  42. if($s->check('hash')) {
  43. $hash = $s->read('hash');
  44. } else {
  45. $hash = $this->Pwd->alphaNumPass();
  46. $s->write('hash',$hash);
  47. }
  48. $title = $this->data['Post']['title'];
  49. $body = trim($this->data['Post']['body']);
  50. $body = explode("\n",$body);
  51. $body[0] = trim($body[0]);
  52. $_size = 0;
  53. $_tsize = 0;
  54. if(!isset($body[1])) {
  55. $_size += 19;
  56. $_tsize += 11;
  57. } elseif((bool)(isset($body[1]) and !isset($body[2]))) {
  58. $_size += 8;
  59. }
  60. $u->file_new_name_body = 'img';
  61. $u->allowed = array('image/*');
  62. $u->image_convert = 'png';
  63. $u->image_resize = true;
  64. $u->image_x = 440;
  65. $u->image_safe_name = false;
  66. $u->image_ratio_y = true;
  67. $res = $u->process();
  68. $img = imagecreatefromstring($res);
  69. imagejpeg($img,WWW_ROOT.'pic/sess/'.$now.'-1'.$s->read('hash').'.jpg',100);
  70. imagedestroy($img);
  71. unset($res);
  72. $u->allowed = array('image/*');
  73. $u->image_convert = 'png';
  74. $u->image_resize = true;
  75. $u->image_x = 436;
  76. $u->image_ratio_y = true;
  77. $u->image_border_color = '#FFFFFF';
  78. $u->image_border = '2px 2px 2px 2px';
  79. $res = $u->process();
  80. if($u->processed) {
  81. $img = imagecreatefromstring($res);
  82. unset($res);
  83. $height = ($u->image_dst_y + 138);
  84. $bg = imagecreatetruecolor(500,$height);
  85. imagecopy($bg, $img,30,30,0,0,440,$height);
  86. $black = imagecolorallocate($bg,0,0,0);
  87. $white = imagecolorallocate($bg,255,255,255);
  88. $font = WWW_ROOT.'fonts/DejaVuSerif.ttf';
  89. $bbox = imagettfbbox(18,0,$font,$title);
  90. $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
  91. $y = ($u->image_dst_y + 58 + $_tsize);
  92. imagettftext($bg,18,0,$x,$y,$white,$font,$title);
  93. $bbox = imagettfbbox(10,0,$font,$body[0]);
  94. $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
  95. $y = ($u->image_dst_y + 78 + $_size);
  96. imagettftext($bg,10,0,$x,$y,$white,$font,$body[0]);
  97.  
  98. if(isset($body[1])) {
  99. $body[1] = trim($body[1]);
  100. $bbox = imagettfbbox(10,0,$font,$body[1]);
  101. $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
  102. $y = ($u->image_dst_y + 96 + $_size);
  103. imagettftext($bg,10,0,$x,$y,$white,$font,$body[1]);
  104. }
  105. if(isset($body[2])) {
  106. $body[2] = trim($body[2]);
  107. $bbox = imagettfbbox(10,0,$font,$body[2]);
  108. $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
  109. $y = ($u->image_dst_y + 114);
  110. imagettftext($bg,10,0,$x,$y,$white,$font,$body[2]);
  111. }
  112. $gray = imagecolorallocate($bg,80,80,80);
  113. $bbox = imagettfbbox(8,0,$font,$_SERVER['HTTP_HOST']);
  114. $x = $bbox[0] + (imagesx($bg) / 2) - ($bbox[4] / 2);
  115. $y = ($u->image_dst_y + 134);
  116. imagettftext($bg,8,0,$x,$y,$gray,$font,$_SERVER['HTTP_HOST']);
  117. imagejpeg($bg, WWW_ROOT.'pic/sess/'.$now.'-2'.$s->read('hash').'.jpg',100);
  118. imagedestroy($img);
  119. imagedestroy($bg);
  120. if(!$s->check('id')) {
  121. $this->Post->create();
  122. } else {
  123. $this->Post->id =(int) $s->read('id');
  124. }
  125. $this->Post->set('public',2);
  126. $this->Post->save(array(
  127. 'Post'=>array(
  128. 'id'=>$this->Post->id,
  129. 'user_id'=>$this->Session->read('Auth.User.id'),
  130. 'title'=>Sanitize::html($title),
  131. 'body'=>Sanitize::html($this->data['Post']['body']),
  132. 'img'=>'pic/'.$now.'-'.$hash.'.jpg'),
  133. 'public' => 2
  134. )
  135. );
  136. $s->write('id',$this->Post->id);
  137. $s->write('step2',true);
  138. $s->write('img',$now);
  139. return;
  140. } else {
  141. $s->setFlash('Nie można wgrać zdjęcia.');
  142. return;
  143. }
  144. }
  145. } else {
  146. $u->upload(WWW_ROOT.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg');
  147. if($u->uploaded) {
  148. $u->image_convert = 'jpg';
  149. $u->jpeg_quality = 100;
  150. $u->file_safe_name = false;
  151. $u->file_new_name_body = $s->read('img').'-'.$s->read('hash');
  152. $u->process(WWW_ROOT.'/pic/');
  153. if($u->processed) {
  154. @unlink(WWW_ROOT.'pic/sess/'.$s->read('img').'-1'.$s->read('hash').'.jpg');
  155. @unlink(WWW_ROOT.'pic/sess/'.$s->read('img').'-2'.$s->read('hash').'.jpg');
  156. unset($img,$img2);
  157. $this->Post->id =(int) $s->read('id');
  158. $this->Post->set('public', 0);
  159. $this->Post->set('created',date('Y-m-d H:i:s',strtotime('now')));
  160. $this->Post->set('modified',date('Y-m-d H:i:s',strtotime('now')));
  161. $this->Post->save();
  162. if(!empty($tag)) {
  163. $tag = array_unique($tag);
  164. foreach($tag as $k=>$v) {
  165. if($k==(int) $this->getOpt('max_tags'))
  166. break;
  167. $v = trim($v);
  168. $v = strip_tags($v);
  169. $t = $this->Tag->findByName($v);
  170. if($t) {
  171. $this->PostsTag->create();
  172. $this->Tag->id=$t['Tag']['id'];
  173. $this->Tag->save(array('Tag'=>array('post_count'=>($t['Tag']['post_count']+1))));
  174. $this->PostsTag->save(array('PostsTag'=>array('post_id'=>$this->Post->id,'tag_id'=>$t['Tag']['id'])));
  175. continue;
  176. }
  177. $this->Tag->create();
  178. $this->Tag->save(array('Tag'=>array('name'=>trim($v),'post_count'=>1)));
  179. $this->PostsTag->create();
  180. $this->PostsTag->save(array('PostsTag'=>array('post_id'=>$this->Post->id,'tag_id'=>$this->Tag->id)));
  181. }
  182. }
  183. $s->del('id');
  184. $s->del('step2');
  185. $s->del('img');
  186. $s->del('hash');
  187. $this->redirect('/view/'.$this->Post->id);
  188. }
  189. }
  190. }
  191. }
  192. }


Proszę o pomoc, z góry dziękuję!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.