Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Deprecated: Non-static method WP_MatchesMapRegex::apply() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-includes/class-wp.php on line 207
Записки профессора » Создаем анимированный gif используя php и ImageMagick
Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/general-template.php on line 1643

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::LoadStyles() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 405
Главная > PHP > Создаем анимированный gif используя php и ImageMagick

Создаем анимированный gif используя php и ImageMagick


Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

Deprecated: Non-static method CodeColorerOptions::ParseOptions() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 80

Deprecated: Non-static method CodeColorerOptions::PopulateDefaultValues() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 66

Deprecated: Non-static method CodeColorerOptions::FilterLanguage() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 102

Deprecated: Non-static method CodeColorerOptions::GetLanguageMappings() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 246

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 157

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 173

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 69

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 72

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 75

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 78

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 81

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 84

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 87

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/thumbnail-viewer/wp-thumbnailviewer.php on line 78

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

0_1a49a_d5293a56_XLМетоды ImageMagick до сих пор плохо документированы, а про перевод я вообще молчу.

Возникла необходимость делать презентации к галерее. Изначально задача ставилась делать презентацию в формате avi или mpeg, но после более детального рассмотрения задачи было решено делать ее в формате GIF (так и проще, и дешевле, и быстрей, и презентация меньше весит).
Искал в гугле по данному вопросу попадаются форумы где люди спрашивают как сделать, но внятного ответа я там не нашел. В основном там затрагиваются вопросы ресайза анимированных картинок. Но это немного другое.

Ответ я нашел… не поверите…в мануале =) да, кто бы мог подумать? (сарказм)
Знаете основное правило любого хорошего продавца? “Показывать товар там где его ищет покупатель”
Так вот решение своей проблемы я искал совершенно не там где, вероятно должен был бы искать, по мнению “продавцов”. А нашел чисто случайно статью, где использовалась функция addImage. Вроде все понятно по названию как она работает, но что-то у меня с ней не заладилось, и я полез в мануал. Она, как и многое не документирована, но есть всего 1 пример, который полностью реализует нужный мне функционал. И так я его здесь и приведу с небольшими своими поправками.
Вот весь код:

/*
* Создаем анимированый gif из списка картинок
*/

        $filelist = array('images_1.jpg','images_2.jpg','images_3.jpg',);
 
        $aniGif = new Imagick();
        $aniGif->setFormat("gif");
 
        foreach ($filelist as $frameitem) {
            $frame = new Imagick($frameitem);
            $frame->setImageDelay(300);
            $aniGif->addImage($frame);
        }
        $aniGif->writeImages("aniGif.gif", true);

Ну вроде все понятно и просто. Будут вопросы, задавайте, возможно я даже смогу на них ответить =)

Лирическое отступление :
Если у Вас с английским все в порядке, есть немного свободного времени, и желание внести свой вклад перевод той документации которая есть на данный момент, то это можно сделать здесь.

Поделиться в соц. сетях

Опубликовать в Google Buzz
Опубликовать в Google Plus
Опубликовать в LiveJournal
Опубликовать в Мой Мир
Опубликовать в Одноклассники
Опубликовать в Яндекс

PHP ,

  1. Leamm
    22 Март 2011 из 13:31 | #1

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Не подскажите, как включить циклическую анимацию? А то доходит до последнего кадра и останавливается.

    • 22 Март 2011 из 13:44 | #2

      Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

      Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

      Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

      Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

      Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

      Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

      Вы уверенны что все сделали так как у меня написано?
      У меня циклически повторяется процесс.
      Вот пример анимация

  2. Leamm
    22 Март 2011 из 13:52 | #3

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Всё как в примере, только кадра у меня два и они в gif формате.

  3. Leamm
    22 Март 2011 из 14:09 | #4

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Пробовал jpg в качестве исходных изображений, анимация зациклилась.

  4. 22 Март 2011 из 14:21 | #5

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Ничего сказать по данному вопросу к сожалению не могу. Странно что при формате GIF цикла не происходит.

  5. 22 Март 2011 из 14:21 | #6

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Как вариант переводите изображение в JPG и потом создавайте GIF

  6. Leamm
    22 Март 2011 из 17:12 | #7

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Теперь проблема с отображением.
    В случае сохранения
    $aniGif->writeImages(“test.gif”, true);
    анимация работает.

    Когда вывожу в браузер
    header(‘Content-type:image/gif’);
    echo $aniGif;
    анимация не работает.

  7. Leamm
    22 Март 2011 из 17:23 | #8

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

    Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

    Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

    Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

    Решил проблему:
    echo $aniGif->getImagesBlob();

  1. Трекбеков пока нет.