Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Problem tłem przy zmniejszaniu obrazków
Forum PHP.pl > Forum > Przedszkole
northwest
Witam serdecznie,
mam taki kod:
  1. function createThumbnail($path, $imagename, $rozmiar) { /////// tworzymy miniaturkę
  2. $wynik = explode(".", $imagename);
  3. $type = $wynik[1];
  4.  
  5. $site_max_thumbnails_size = $rozmiar; // max size
  6. if ($type== "jpg" || $type== "jpeg"){
  7. $img = imagecreatefromjpeg( "{$path}{$imagename}" );
  8. }
  9. if ($type== "png"){
  10. $img = imagecreatefrompng( "{$path}{$imagename}" );
  11. }
  12. if ($type== "gif"){
  13. $img = imagecreatefromgif( "{$path}{$imagename}" );
  14. }
  15. $width = imagesx( $img );
  16. $height = imagesy( $img );
  17.  
  18. // calculate thumbnail size
  19. if ($height>=$width) {
  20. $smallerSize=$width;
  21. $croppingStartHeight=($height-$smallerSize)/2;
  22. $croppingStartWidth=0;
  23. }
  24. else {
  25. $smallerSize=$height;
  26. $croppingStartHeight=0;
  27. $croppingStartWidth=($width-$smallerSize)/2; }
  28. $croppedImage=imagecreatetruecolor($smallerSize, $smallerSize); // create square image
  29. $resizedImage=imagecreatetruecolor($site_max_thumbnails_size, $site_max_thumbnails_size);
  30. imagecopy($croppedImage, $img, 0, 0, $croppingStartWidth, $croppingStartHeight, $smallerSize, $smallerSize); // build cropped, square image
  31. imagecopyresampled ($resizedImage, $croppedImage, 0, 0, 0, 0, $site_max_thumbnails_size, $site_max_thumbnails_size, $smallerSize, $smallerSize); // copy and resize old image into new image
  32. $pathToThumbs=$path."";
  33. if ($type== "jpg" || $type== "jpeg"){
  34. if (!imagejpeg($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file
  35. $result='Nie można zapisać miniaturki w folderze docelowym!';
  36. ImageDestroy($croppedImage);
  37. ImageDestroy($resizedImage);
  38. return $result;
  39. }
  40. if ($type== "png"){
  41. if (!imagepng($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file
  42. $result='Nie można zapisać miniaturki w folderze docelowym!';
  43. ImageDestroy($croppedImage);
  44. ImageDestroy($resizedImage);
  45. return $result;
  46. }
  47. if ($type== "gif"){
  48. if (!imagegif($resizedImage, "{$pathToThumbs}mini_{$imagename}" )) // save thumbnail into a file
  49. $result='Nie można zapisać miniaturki w folderze docelowym!';
  50. ImageDestroy($croppedImage);
  51. ImageDestroy($resizedImage);
  52. return $result;
  53. }
  54. }


przy wgrywaniu i obróbce przeźroczystych PNG mam czarne tło sad.gif jak pozostawić przeźroczyste po zmniejszeniu?



Z góry dziękuje za pomoc,
Northwest
thek
A o imagealphablending i/lub imagesavealpha słyszał? smile.gif
northwest
tak,ale nie wiem jak "wkomponować" to sad.gif

zrobiłem coś takiego:
  1. $croppedImage=imagecreatetruecolor($smallerSize, $smallerSize); // create square image
  2. imagesavealpha($croppedImage, true);
  3. $resizedImage=imagecreatetruecolor($site_max_thumbnails_size, $site_max_thumbnails_size);
  4. imagesavealpha($resizedImage, true);


ale niestety nie pomogło sad.gif

kurcze, nie wiem jak to zmienić sad.gif a jak ustawić np. domyslnie zielone tło zamiast czarnego?
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.