Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [GD] Obrazek kolorowy i czarnobiały
sebekzosw
post
Post #1





Grupa: Zarejestrowani
Postów: 437
Pomógł: 42
Dołączył: 16.04.2007

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


Witam,

chciałbym, aby na jednym obrazku był obrazek kolorowy i szary - tak to całość wychodzi szara:

  1. <?php
  2.  
  3. function createThumb($imgSrc, $thumbnail_width, $thumbnail_height)
  4. {
  5. list($width_orig, $height_orig) = getimagesize($imgSrc);
  6. $myImage = imagecreatefromjpeg($imgSrc);
  7. $ratio_orig = $width_orig / $height_orig;
  8.  
  9. if($thumbnail_width / $thumbnail_height > $ratio_orig)
  10. {
  11. $new_height = $thumbnail_width / $ratio_orig;
  12. $new_width = $thumbnail_width;
  13. } else
  14. {
  15. $new_width = $thumbnail_height * $ratio_orig;
  16. $new_height = $thumbnail_height;
  17. }
  18.  
  19. $x_mid = $new_width / 2; //horizontal middle
  20. $y_mid = $new_height / 2; //vertical middle
  21.  
  22. $process = imagecreatetruecolor(round($new_width), round($new_height));
  23.  
  24. imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
  25. $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
  26. imagecopyresampled($thumb, $process, 0, 0, ($x_mid - ($thumbnail_width / 2)), ($y_mid - ($thumbnail_height / 2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
  27.  
  28. imagedestroy($process);
  29. imagedestroy($myImage);
  30. return $thumb;
  31. }
  32.  
  33. header('Content-Type: image/jpeg');
  34.  
  35. $new = imagecreatetruecolor(135, 285);
  36. $bgColor = imagecolorallocate($new, 255, 255, 255);
  37. imagefilledrectangle($new, 0, 0, 135, 285, $bgColor);
  38.  
  39. $img = createThumb("http://www.blog.twardowscy.pl/pliki/galeria/home/img8.jpg", 135, 135); //miniaturka
  40. $img2 = $img;
  41. imagefilter($img2, IMG_FILTER_GRAYSCALE);
  42.  
  43. imagecopyresized($new, $img, 0, 0, 0, 0, 135, 135, 135, 135);
  44. imagecopyresized($new, $img2, 0, 145, 0, 0, 135, 135, 135, 135);
  45.  
  46. imagejpeg($new, '', 100);
  47.  
  48. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 21.08.2025 - 23:06