Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] Nakładanie obrazka w bibliotece GD
Piro
post
Post #1





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 5.07.2008

Ostrzeżenie: (0%)
-----


Witam

Chciałbym dodać swoje logo do obrazka uploadowanego na serwer ale wystąpił mały problem... Używam biblioteki GD v2 i dodając obrazek *.png na *.jpg nie działa mi skrypt... Wiem że tak nie powinno się robić ale nie mam innego sposobu. Nie chcę żeby obrazek który ma się znajdować na wrzuconym był z białymi "lukami" dlatego dałem png. Gdyby ktoś miał pomysł na to jak rozwiącać ten problem to proszę napisać.

Pozdrawiam Piro
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Piro
post
Post #2





Grupa: Zarejestrowani
Postów: 56
Pomógł: 0
Dołączył: 5.07.2008

Ostrzeżenie: (0%)
-----


Oto skrypt:
  1. <?php
  2. Oto skrypt<span style="color: #007700":
  3. [PHP]
  4.    if($ext == jpg || $ext == jpeg){
  5.            $logo_path = 'galeria/logo.png';
  6.            $logo_mini_path = 'galeria/logo2.png';
  7.            $img = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/zdjecie$i.$ext");
  8.            $width  = imagesx($img);
  9.              $height = imagesy($img);
  10.              echo "<br/>$width&nbsp: $height<br/>";
  11.              if($width > 1024 || $height > 1024){
  12.                  if ($width > $height){
  13.                     $x = 1024/$width;
  14.                     echo "<br/>$x<br/>";
  15.                     $width_mini = $width * $x;
  16.                     $height_mini = $height * $x;
  17.                     echo "<br/>$width_mini&nbsp: $height_mini<br/>";
  18.                     $img_mini = imagecreatetruecolor($width_mini, $height_mini);
  19.                    imagecopyresampled($img_mini, $img, 0, 0, 0, 0, $width_mini ,                         $height_mini, $width  , $height);
  20.                    imagejpeg($img_mini, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_full.$ext", 80);
  21.                    $logo_full = imagecreatefrompng( $logo_path );
  22.                   $zdjecie_po = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_full.$ext");
  23.                    imagecopy($zdjecie_po, $logo_full, 80, 80, 0, 0, $width_mini ,                         $height_mini);
  24.                    imagejpeg($zdjecie_po, '', 80);
  25.                    imagedestroy($img_mini);
  26.                    $y = 100/$width;
  27.                     echo "<br/>$y<br/>";
  28.                     $width_mini2 = $width * $y;
  29.                     $height_mini2 = $height * $y;
  30.                     echo "<br/>$width_mini2&nbsp: $height_mini2<br/>";
  31.                     $img_mini2 = imagecreatetruecolor($width_mini2, $height_mini2);
  32.                    imagecopyresampled($img_mini2, $img, 0, 0, 0, 0, $width_mini2 ,                         $height_mini2, $width  , $height);
  33.                    imagejpeg($img_mini2, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext", 80);
  34.                    $logo_mini = imagecreatefrompng( $logo_mini_path );
  35.                   $zdjecie_po2 = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext");
  36.                    imagecopy($zdjecie_po2, $logo_mini, 15, 15, 0, 0, $width_mini2 ,                         $height_mini2);
  37.                    imagejpeg($zdjecie_po2, '', 80);
  38.                    imagedestroy($img);
  39.                    imagedestroy($img_mini2);
  40.                 } else {
  41. ?>

W następnym poście cd...
Jeżeli któreś zmienne potrzebują objaśnienie to proszę pytać...

$userdata['username'] - trzyma nazwę użytkownika pobraną z phpbb
$f - kolejna liczba która ma zostać przypisana folderowi

CD.. skryptu
  1. <?php
  2. $x = (1024/$height);
  3.                      $width_mini = $width * $x;
  4.                      $height_mini = $height * $x;
  5.                      $img_mini = imagecreatetruecolor($width_mini, $height_mini);
  6.                     imagecopyresampled($img_mini, $img, 0, 0, 0, 0, $width_mini ,                             $height_mini, $width  , $height);
  7.                     imagejpeg($img_mini, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_full.$ext", 80);
  8.                     $logo_full = imagecreatefrompng( $logo_path );
  9.                    $zdjecie_po = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_full.$ext");
  10.                     imagecopy($zdjecie_po, $logo_full, 80, 80, 0, 0, $width_mini ,                         $height_mini);
  11.                     imagejpeg($zdjecie_po, '', 80);
  12.                     imagedestroy($img_mini);
  13.                     $y = 100/$height;
  14.                      echo "<br/>$y<br/>";
  15.                      $width_mini2 = $width * $y;
  16.                      $height_mini2 = $height * $y;
  17.                      echo "<br/>$width_mini2&nbsp: $height_mini2<br/>";
  18.                      $img_mini2 = imagecreatetruecolor($width_mini2, $height_mini2);
  19.                     imagecopyresampled($img_mini2, $img, 0, 0, 0, 0, $width_mini2 ,                         $height_mini2, $width  , $height);
  20.                     imagejpeg($img_mini2, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext", 80);
  21.                     $logo_mini = imagecreatefrompng( $logo_mini_path );
  22.                    $zdjecie_po2 = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext");
  23.                     imagecopy($zdjecie_po2, $logo_mini, 15, 15, 0, 0, $width_mini2 ,                         $height_mini2);
  24.                     imagejpeg($zdjecie_po2, '', 80);
  25.                     imagedestroy($img);
  26.                     imagedestroy($img_mini2);
  27.                  }
  28.              } else {
  29.                  if ($width > $height){
  30.                      $y = 100/$width;
  31.                      echo "<br/>$y<br/>";
  32.                      $width_mini2 = $width * $y;
  33.                      $height_mini2 = $height * $y;
  34.                      echo "<br/>$width_mini2&nbsp: $height_mini2<br/>";
  35.                      $img_mini2 = imagecreatetruecolor($width_mini2, $height_mini2);
  36.                     imagecopyresampled($img_mini2, $img, 0, 0, 0, 0, $width_mini2 ,                         $height_mini2, $width  , $height);
  37.                     imagejpeg($img_mini2, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext", 80);
  38.                     $logo_mini = imagecreatefrompng( $logo_mini_path );
  39.                    $zdjecie_po2 = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext");
  40.                     imagecopy($zdjecie_po2, $logo_mini, 15, 15, 0, 0, $width_mini2 ,                         $height_mini2);
  41.                     imagejpeg( $zdjecie_po2, '', 80);
  42.                     imagedestroy($img);
  43.                     imagedestroy($img_mini2);
  44.                  } else {
  45. ?>


To jest tylko fragment odpowiedzialny za tworzenie i dodawanie loga...

  1. <?php
  2. $y = 100/$height;
  3.                      echo "<br/>$y<br/>";
  4.                      $width_mini2 = $width * $y;
  5.                      $height_mini2 = $height * $y;
  6.                      echo "<br/>$width_mini2&nbsp: $height_mini2<br/>";
  7.                      $img_mini2 = imagecreatetruecolor($width_mini2, $height_mini2);
  8.                     imagecopyresampled($img_mini2, $img, 0, 0, 0, 0, $width_mini2 ,                         $height_mini2, $width  , $height);
  9.                     imagejpeg($img_mini2, "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext", 80);
  10.                     $logo_mini = imagecreatefrompng( $logo_mini_path );
  11.                    $zdjecie_po2 = imagecreatefromjpeg("galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_mini.$ext");
  12.                     imagecopy($zdjecie_po2, $logo_mini, 15, 15, 0, 0, $width_mini2 ,                         $height_mini2);
  13.                     imagejpeg($zdjecie_po2, '', 80);
  14.                     imagedestroy($img);
  15.                     imagedestroy($img_mini2);
  16.                  }
  17.                  rename ("galeria/".$userdata['username']."/galeria".$f."/zdjecie$i.$ext", "galeria/".$userdata['username']."/galeria".$f."/$nazwa2"."_full.$ext");
  18.              }
  19. ?>


To już koniec... jeżeli ktoś chce zobaczyć cały to proszę powiedzieć to gdzieś go udostępnie...
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 7.10.2025 - 16:53