Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Tworzenie zdjęcia
Forum PHP.pl > Forum > Przedszkole
marcin0077
Witam

Mam skrypt który tworzy zdjęcie (wymiary, nazwę, jakość itd.) i chciałbym aby skrypt skopiował/stworzył to zdjęcie jeszcze do innego folderu ale w oryginalnym wymiarze i jakości.

Kod:
  1. <?php
  2.  
  3. header('Content-type: text/html; charset=utf-8');
  4.  
  5. class demotkonv
  6. {
  7. var $szer_gl=600; // szerokoĹ?Ä? obrazka razem z czarnym tĹ?em
  8. var $szer_img=600; // szerokoĹ?Ä? gĹ?Ăłwnego obrazka w ramce
  9. var $top_img=0; // gĂłrny margines
  10. var $font_file = 'Thunderpic/arial.ttf';
  11. var $font_size_tyt = 18;
  12. var $font_size_opis = 10;
  13. var $odstep_miedzy_wierszami = 5;
  14. var $odstep_pod_obrazkiem=0;
  15. var $odstep_pod_tytulem=0;
  16. var $odstep_pod_opisem=0;
  17.  
  18. var $katalog='_picbase/';
  19. var $katalog_tmp='tmp/';
  20. var $znak_wodny='Thunderpic/logo.png';
  21. var $znak_wodny_p='pd'; // lg-lewa gĂłra; pg-prawa gĂłra; ld- lewa dĂłĹ?; pd - prawa dĂłĹ?
  22.  
  23. // tego nie modyfikujemy
  24. var $wys_img=0;
  25. var $wys_gl=0;
  26. var $fname;
  27. var $fotile;
  28.  
  29. function doname($dane)
  30. {
  31. $dane=stripslashes($dane);
  32. $dozwolone='qwertyuiopasdfghjklzxcvbnm1234567890.';
  33. for($i=0;$i<strlen($dane);$i++)
  34. if(eregi(strtolower($dane[$i]),$dozwolone)) $dane2.=$dane[$i];
  35.  
  36. $dop=substr(time(),-4);
  37. return $dop.$dane2;
  38. }
  39.  
  40. function pobierz_upload($filename)
  41. {
  42. $this->fname=$this->doname($filename['name']);
  43.  
  44. $uploadFile = $this->katalog_tmp.$this->fname;
  45. if (move_uploaded_file($filename['tmp_name'], $uploadFile))
  46. {
  47. return $uploadFile;
  48. }
  49. else
  50. return 'NIEPOBRANO';
  51. }
  52.  
  53. function podziel($dane,$dl,$mm)
  54. {
  55. if($mm>6) return $dane; else $mm++;
  56. if(strlen($dane)>$dl)
  57. {
  58. $tt[0]=substr($dane, 0, $dl);
  59. $tt[1]=$this->podziel(substr($dane, $dl,strlen($dane)),$dl,$mm);
  60. return $tt[0].' '.$tt[1];
  61. }
  62. else
  63. return $dane;
  64. }
  65.  
  66. function utworz_img($imgname,$tytul,$opis,$znakuj,$tofilename)
  67. {
  68.  
  69. if( (eregi('\.jpg$',$imgname)) || (eregi('\.jpeg$',$imgname)) )
  70. $img = @imagecreatefromjpeg($katalog_tmp.$imgname);
  71. else if(eregi('\.gif$',$imgname))
  72. {
  73. $img = @imagecreatefromgif($katalog_tmp.$imgname);
  74. $this->fname=str_replace('.gif', '.jpg',$this->fname);
  75. }
  76. else if(eregi('\.png$',$imgname))
  77. {
  78. $img = @imagecreatefrompng($katalog_tmp.$imgname);
  79. $this->fname=str_replace('.png', '.jpg',$this->fname);
  80. }
  81. else
  82. {
  83. return false;
  84. }
  85.  
  86.  
  87. $wys=imagesy($img);
  88. $szer=imagesx($img);
  89.  
  90. $this->wys_img=$wys*($this->szer_img/$szer);
  91.  
  92. $b_left=round(($this->szer_gl-$this->szer_img)/2);
  93.  
  94. $bbox = imagettfbbox ($this->font_size_tyt, 0, $this->font_file, $tytul);
  95. $bbox2 = imagettfbbox ($this->font_size_opis, 0, $this->font_file, $opis);
  96. $wys_bbox=$bbox[5];
  97. $wys_bbox2=$bbox2[5];
  98.  
  99. $mase = $bbox[0] + $bbox[2];
  100. $mase2 = $bbox2[0] + $bbox2[2];
  101.  
  102. $dop_wys=ceil(ceil($mase/$this->szer_img)*($bbox[5]*-1))+ceil((ceil($mase/$this->szer_img)-1)*$this->odstep_miedzy_wierszami)+$this->odstep_pod_obrazkiem-$this->odstep_miedzy_wierszami;
  103. $dop_wys2=ceil(ceil($mase2/$this->szer_img)*($bbox2[5]*-1))+ceil((ceil($mase2/$this->szer_img)-1)*$this->odstep_miedzy_wierszami)+$this->odstep_pod_tytulem-$this->odstep_miedzy_wierszami;
  104.  
  105. $this->wys_gl=$this->wys_img+$this->top_img+20+$dop_wys+$dop_wys2+$this->odstep_pod_opisem;
  106.  
  107. $im = ImageCreateTrueColor( $this->szer_gl, $this->wys_gl );
  108.  
  109. $background_color = imagecolorallocate($im, 0, 0, 0);
  110. $text_color = imagecolorallocate($im, 255, 255, 255);
  111.  
  112. $im2 = ImageCreateTrueColor( $this->szer_img+2, $this->wys_img+2 );
  113.  
  114.  
  115.  
  116. imagecopy( $im, $im2, $b_left-1, $this->top_img-1, 0, 0, $this->szer_img+2, $this->wys_img+2);
  117. imagecopyresampled( $im, $img, $b_left, $this->top_img, 0, 0, $this->szer_img, $this->wys_img, $szer, $wys);
  118.  
  119. if($znakuj && !empty($this->znak_wodny))
  120. {
  121. if( (eregi('.jpg',$this->znak_wodny)) || (eregi('.jpeg',$this->znak_wodny)) )
  122. $imw = @imagecreatefromjpeg($this->znak_wodny);
  123. else if(eregi('.gif',$this->znak_wodny))
  124. $imw = @imagecreatefromgif($this->znak_wodny);
  125. else if(eregi('.png',$this->znak_wodny))
  126. $imw = @imagecreatefrompng($this->znak_wodny);
  127.  
  128. $wys_w=imagesy($imw);
  129. $szer_w=imagesx($imw);
  130.  
  131. if($this->znak_wodny_p=='lg')
  132. {
  133. $b_left2=$b_left+10;
  134. $b_top2=$this->top_img+10;
  135. }
  136. else if($this->znak_wodny_p=='pg')
  137. {
  138. $b_left2=$b_left+($this->szer_img-$szer_w-10);
  139. $b_top2=$this->top_img+10;
  140. }
  141. else if($this->znak_wodny_p=='ld')
  142. {
  143. $b_left2=$b_left+10;
  144. $b_top2=$this->top_img+($this->wys_img-$wys_w-10);
  145. }
  146. else if($this->znak_wodny_p=='pd')
  147. {
  148. $b_left2=$b_left+($this->szer_img-$szer_w-2);
  149. $b_top2=$this->top_img+($this->wys_img-$wys_w-2);
  150. }
  151. imagecopy( $im, $imw, $b_left2, $b_top2, 0, 0, $szer_w, $wys_w);
  152. }
  153.  
  154. $tyt_top=$this->wys_img+$this->top_img+$this->odstep_pod_obrazkiem-$bbox[5];
  155.  
  156. if($mase > $this->szer_img)
  157. {
  158. $ile=$mase/$this->szer_img;
  159. $ile_str=ceil(strlen($tytul)/$ile);
  160. $ile=ceil($ile);
  161. $tytul=str_replace(',',', ',$tytul);
  162. $tytul=str_replace('.','. ',$tytul);
  163. $tb=explode(' ',$tytul);
  164. for($i=0;$i<count($tb);$i++)
  165. $tq[]=$this->podziel($tb[$i],$ile_str,0);
  166.  
  167. $tytul=implode(' ',$tq);
  168.  
  169. $tb=explode(' ',$tytul);
  170. $licz=strlen($tb[0]);
  171. for($i=0;$i<count($tb);$i++)
  172. {
  173. $j=$i+1;
  174. $licz+=strlen($tb[$j]);
  175. $tyt=$tyt.''.$tb[$i].' ';
  176. if($licz>$ile_str)
  177. {
  178. $tc[]=$tyt;
  179. $tyt='';
  180. $licz=strlen($tb[$j]);
  181. }
  182. }
  183. $tc[]=$tyt;
  184. $tyt='';
  185. $licz=strlen($tb[$j]);
  186.  
  187. for($i=0;$i<=$ile;$i++)
  188. {
  189. $tytul2=$tc[$i];
  190. $bbox = imagettfbbox ($this->font_size_tyt, 0, $this->font_file, $tytul2);
  191. $mase = $bbox[0] + $bbox[2];
  192. $dl_tyt = $b_left+round(($this->szer_img - $mase)/2);
  193. imagefttext($im, $this->font_size_tyt, 0, $dl_tyt, $tyt_top, $text_color, $this->font_file, $tytul2);
  194. $tyt_top+=$this->odstep_miedzy_wierszami+($bbox[5]*-1);
  195. }
  196. }
  197. else
  198. {
  199. $dl_tyt = $b_left+round(($this->szer_img - $mase)/2);
  200. imagefttext($im, $this->font_size_tyt, 0, $dl_tyt+1, $tyt_top, $text_color, $this->font_file, $tytul);
  201. $tyt_top+=$this->odstep_miedzy_wierszami+($bbox[5]*-1);
  202. }
  203.  
  204. $tyt_top+=$this->odstep_pod_tytulem+$wys_bbox;
  205.  
  206. unset($tc);
  207. unset($tq);
  208. $licz=0;
  209.  
  210. if($mase2 > $this->szer_img)
  211. {
  212. $ile=$mase2/$this->szer_img;
  213. $ile_str=ceil(strlen($opis)/$ile);
  214. $ile=ceil($ile);
  215. $opis=str_replace(',',', ',$opis);
  216. $opis=str_replace('.','. ',$opis);
  217. $tb=explode(' ',$opis);
  218. for($i=0;$i<count($tb);$i++)
  219. $tq[]=$this->podziel($tb[$i],$ile_str,0);
  220.  
  221. $opis=implode(' ',$tq);
  222. $tb=explode(' ',$opis);
  223. $licz=strlen($tb[0]);
  224. $tyt='';
  225. for($i=0;$i<count($tb);$i++)
  226. {
  227. $j=$i+1;
  228. $licz+=strlen($tb[$j])+1;
  229. $tyt=$tyt.''.$tb[$i].' ';
  230. if($licz>$ile_str)
  231. {
  232. $tc[]=$tyt;
  233. $tyt='';
  234. $licz=strlen($tb[$j]);
  235. }
  236. }
  237. $tc[]=$tyt;
  238. $tyt='';
  239. $licz=strlen($tb[$j]);
  240.  
  241. for($i=0;$i<=$ile;$i++)
  242. {
  243. $opis2 = $tc[$i];
  244. $bbox2 = imagettfbbox($this->font_size_opis, 0, $this->font_file, $opis2);
  245. $mase2 = $bbox2[0] + $bbox2[2];
  246. $dl_tyt = $b_left+round(($this->szer_img - $mase2)/2);
  247. imagefttext($im, $this->font_size_opis, 0, $dl_tyt, $tyt_top, $text_color, $this->font_file, $opis2);
  248. $tyt_top+=$this->odstep_miedzy_wierszami+($bbox2[5]*-1);
  249. }
  250. }
  251. else
  252. {
  253. $dl_tyt = $b_left+round(($this->szer_img - $mase2)/2);
  254. imagefttext($im, $this->font_size_opis, 0, $dl_tyt,$tyt_top, $text_color, $this->font_file, $opis);
  255. $tyt_top+=$this->odstep_miedzy_wierszami+($bbox2[5]*-1);
  256. }
  257. imagejpeg($im, "_picbase/" . $tofilename,75);
  258. $im_orginal = ImageCreateTrueColor($szer,$wys);
  259. imagejpeg($im_orginal, "_orginal/" . $tofilename,100);
  260. @unlink($this->katalog_tmp.$this->fname);
  261.  
  262. return $this->katalog.$this->fname;
  263. }
  264. }
  265.  
  266.  
  267. ?>


Kilka lini wyżej dodałem taki kod:
  1. $im_orginal = ImageCreateTrueColor($szer,$wys);
  2. imagejpeg($im_orginal, "_orginal/" . $tofilename,100);

Zdjęcie tworzy się całe czarne. Z tego co się domyślam to nie jest pobierane zdjęcie i dlatego tak się dzieje, mimo to nie mogę tego ogarnąć. Proszę o pomoc.
nospor
Cytat
i chciałbym aby skrypt skopiował/stworzył to zdjęcie jeszcze do innego folderu ale w oryginalnym wymiarze i jakości i tej samej nazwie.

Czasami jak tak patrze jak kombinujecie jak koń pod górkę to.... to nie wiem co smile.gif
Skoro chcesz skopiować zdjęcie i mieć dokładnie to samo to je poprostu skopiuj. Zdjecie to normalny plik.
http://il.php.net/manual/en/function.copy.php
marcin0077
Nie idzie. Nie ogarniam tego.
nospor
A co tu ogarniać?
copy('skad kopiujesz', 'dokąd kopiujesz');
marcin0077
robiłem coś takiego:
copy(/tmp/$img, _orginal/$img)
i pojawia się biała strona podczas dodawania
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.