Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Zmniejszenie animowanego GIFa
deha21
post 5.03.2015, 21:14:55
Post #1





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

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


Potrzebuję zmniejszyć rozmiar(rozdzielczość) animowanego GIFa. Mam taki kod jak poniżej. Wszysko się pomniejsza i dodaje watermark, ale jest stopklatka a chciałbym, żeby GIF pozostał animowany. Czytałem w necie o różnych bibliotekach, które to umożliwiają. Niestety nie mogą żadnej dodać. Czy jest możliwość zrobić to jakoś bez bibliotek?
(ten kawałek który wykomentował jest chyba nie potrzebny, bo bez tego działa tak jak działało; znalazłem w necie i myślałem, że pomoże przy GIFie ale nie)
  1. function watermark($filef, $new_width, $new_height, $quality) {
  2.  
  3. $info = getimagesize($filef);
  4. if ($info === false) { return false; }
  5. $img = imagecreatefromgif($filef);
  6.  
  7. $th = imagecreatetruecolor($new_width, $new_height+25);
  8. $watermark = imagecreatefrompng('watermark.png');
  9.  
  10. /*
  11. imagealphablending($th, false);
  12. imagesavealpha($th,true);
  13. $transparent = imagecolorallocatealpha($newImg, 255, 255, 255, 127);
  14. imagefilledrectangle($th, 0, 0, $new_width, $new_height, $transparent);
  15. */
  16.  
  17. imagecopyresampled($th, $img, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]);
  18. imagecopy($th, $watermark, $new_width-142, $new_height, 0, 0, 142, 25);
  19. imagegif($th, $filef, $quality);
  20.  
  21. imagedestroy($th);
  22. imagedestroy($img);
  23. return true;
  24.  
  25. }


Ten post edytował deha21 5.03.2015, 21:16:39


--------------------
Go to the top of the page
+Quote Post
Kshyhoo
post 5.03.2015, 21:17:05
Post #2





Grupa: Opiekunowie
Postów: 3 855
Pomógł: 317
Dołączył: 4.01.2005
Skąd: że




Nie da rady. Jakaś biblioteka sobie radzi z animowanymi GIFami, nie pamiętam która...


--------------------
Go to the top of the page
+Quote Post
deha21
post 5.03.2015, 22:00:55
Post #3





Grupa: Zarejestrowani
Postów: 544
Pomógł: 5
Dołączył: 18.08.2009

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


Znalazłem GifFrameExtractor i GifCreator, które tworzą animowanego GIFa. Problem jest taki, że nie działa teraz watermark. Pewnie dlatego, że nie mam ImageWorkshop który jest chyba wymagany(?). Tutaj mam kawałek użytego kodu:
  1. if (GifFrameExtractor::isAnimatedGif($gifPath)) { // check this is an animated GIF
  2.  
  3. // Extractions of the GIF frames and their durations
  4. $gfe = new GifFrameExtractor();
  5. $frames = $gfe->extract($gifPath);
  6.  
  7. // Initialization of the watermark layer
  8. $watermark = ImageWorkshop::initFromPath('watermark.png');
  9.  
  10. $retouchedFrames = array();
  11.  
  12. // For each frame, we add a watermark and we resize it
  13. foreach ($frames as $frame) {
  14.  
  15. // Initialization of the frame as a layer
  16. $frameLayer = ImageWorkshop::initFromResourceVar($frame['image']);
  17.  
  18. $frameLayer->resizeInPixel($new_width, $new_height+25, true); // Resizing
  19. $frameLayer->addLayerOnTop($watermark, 0, 0, 'RB'); // Watermarking
  20.  
  21. $retouchedFrames[] = $frameLayer->getResult();
  22. }
  23.  
  24. // Then we re-generate the GIF
  25. $gc = new GifCreator();
  26. $gc->create($retouchedFrames, $gfe->getFrameDurations(), 0);
  27.  
  28. // And now save it !
  29. file_put_contents($filef, $gc->getGif());
  30. }


Idzie jakoś do tego dopisać ręcznie dodawanie watermarka, np. jak jak to robiłem wcześniej? Albo czy idzie jakoś sprawdzić czy jest ImageWorkshop zainstalowany? Serwer mam na az.pl i pewnie nie bedzie można dodać biblioteki dodatkowej.


--------------------
Go to the top of the page
+Quote Post

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 Wersja Lo-Fi Aktualny czas: 27.06.2025 - 17:22