Jump to content
horst

Image Animated GIF

Recommended Posts

For a website Iam working on, I tried to use this module with animated gif's.
I know that PW doesn't support resizing animated gif's out of the box, so I also installed the "Image Animated Gif Module".

Now the gif's are animated but have strange artifacts and colors.
When I resize them with PW like "$image->width(320)" they are fine.

Is there anyone having the same problem?
Would be awesome to use this module for all my images!

THX!

Share this post


Link to post
Share on other sites

@jploch: a question from me to clarify:

  • You have installed ImageAnimatedGif module and
  • it produces correct resized and animated variations with calls to pageimage methods (widt, height, size),
  • but it doesn't produce the same result when you use it with MarkupSrcSet?

The ImageAnimatedGif hooks into before pageimage resize, and MarkupSrcSet simply calls pageimage size, so I'm wondering what could be the difference here?

What is the result of MarkupSrcSet? Images are scaled down and animated, but with artefacts? Can you provide an example? (a variation from direct call to pageimage and one result from MarkupSrcSet)

  • Like 2

Share this post


Link to post
Share on other sites
12 hours ago, horst said:

@jploch: a question from me to clarify:

  • You have installed ImageAnimatedGif module and
  • it produces correct resized and animated variations with calls to pageimage methods (widt, height, size),
  • but it doesn't produce the same result when you use it with MarkupSrcSet?

The ImageAnimatedGif hooks into before pageimage resize, and MarkupSrcSet simply calls pageimage size, so I'm wondering what could be the difference here?

What is the result of MarkupSrcSet? Images are scaled down and animated, but with artefacts? Can you provide an example? (a variation from direct call to pageimage and one result from MarkupSrcSet)

Thanks for your quick reply!

Here is my code example (shortened) without MarkupSrcSet and with ImageAnimatedGif installed:

 $image->width(300);
echo ="<img src='{$image->url}'>";

Result:

animation_resize.gif

 


code example with MarkupSrcSet and ImageAnimatedGif installed:

$srcset = $image->srcset('thumbnail', 'inline-block', array('quality' => 70));
echo ="<img $srcset>";

Result:

animation_srcset.gif

Share this post


Link to post
Share on other sites

any news on using this with animated gif's?

I have an image field with various files (gif, png, jpg)
Is there a way to just target gif files and resize them with PW (like 
$image->width(300);)
and use MarkupSrcSet for the rest of the images?

Any help would be appreciated!
 

Share this post


Link to post
Share on other sites

I want to port the animated gif module to the new image rendering engine module type. With this it will automatically handle the animated gifs correct. Maybe I can do it this week / weekend.

  • Like 2

Share this post


Link to post
Share on other sites

@jploch I have tested this and created a new Rendering Engine, but for me, every created variation has the same (wrong) result as your example. It is something in that image that doesn't work right with the lib. I think it is a false transparency for every slide in the animation. Are there other images that behave the same?

In your "working example" that result in correct variation, I belive it is the original image or simply copy of it. You use ->width(300) and the original is 300px. For me, every downscaled variation doesn't work correct.

  • Like 2

Share this post


Link to post
Share on other sites

@jploch The crux is with the transparency of the background. The original image is recognized as a transparent, animated GIF. But the stored transparency color index validates to 0,0,0 (black !)

I have opened your image in photoshop and added 1 layer filled with white to the base of the other 60 layers. The animated resulting GIF is same size as yours with transparency but works with the anim module:

animation_with_white_bg.gif.cf8b7d4e667e3386b0c92489bd7f1c8d.gif

 

To sum up:

  • the anim gif module doesn't work in any case with this sort of images.
  • The culprit is the transparency background.
  • If you are able to add a filled background layer to those images, it will work good with resizing. (test the image above)
  • If you also need the transparent background, you cannot use any sort of variation creation. Workaround could be to determine in template file if it is a GIF (or only if it is an animated GIF) and then use markup with a special css class for displaying those in different sizes, according to media query max-width, for example.

anim-gif-comparision.gif.536820fd266e96ed1debec4d2eddd2fc.gif

Edited by horst
added sum up
  • Like 2

Share this post


Link to post
Share on other sites

@horst  Thanks for explaining the problem!

unfortunately I have to use GIF's with transparency.

  • Quote

    If you also need the transparent background, you cannot use any sort of variation creation. Workaround could be to determine in template file if it is a GIF (or only if it is an animated GIF) and then use markup with a special css class for displaying those in different sizes, according to media query max-width, for example.

    I think that would be the way to go. How would I target GIF's in my template file? Can you give an example?
    Thanks again for your support!

Share this post


Link to post
Share on other sites

@jploch checking the image type:

$image = $page->images->first();

$imageSizer = new ImageSizer($image->filename);
$imageInfo = $imageSizer->getImageInfo(false);

This will return strings like:

jpg

gif
gif-trans
gif-anim
gif-trans-anim

png24
png24-trans
png24-alpha
png8
png8-trans

In your case, when gif-trans-anim is detected, you want to switch to css-workaround.

 

Spoiler

595bf930a49f8_capture_148.thumb.png.a4c4b0f3d7d39992d58993caf7633610.png

 

Share this post


Link to post
Share on other sites

Since today, 31-01-2018, we have support for this in the PW Core. Therefore I updated this module to version 2.0.2

This version handles the detection of the core support and dismiss its installation then. If the core module is available but not installed, it get installed instead of this third party module.

If you have this third party module already installed since a previous PW version and upgrade your wire folder, this module will detect the core module and install it. Its own hook isn't registered then and you get a notification about the changes.

screencapture_01.png.5f7e2004863d5cd921859c7a147458a5.png

screencapture_02.png.fe74975083c685e89385640e7e71c0f8.png

Edited by horst
  • Like 5

Share this post


Link to post
Share on other sites

When I enabled this, a page with a rather oversized gif ran out of memory saving, and then proceeded to return a 500 on the front and back-end 🤪

Share this post


Link to post
Share on other sites
2 hours ago, cst989 said:

When I enabled this, a page with a rather oversized gif ran out of memory saving, and then proceeded to return a 500 on the front and back-end 🤪

a) Please tell a bit more accurate about what you have installed / enabled. (PW version, which gif extension and version.

b) How big is the original anim-gif in filesize?

c) How much memory usage is available for PHP?

Share this post


Link to post
Share on other sites

Sorry I should've been clearer. I used the latest version, ie part of Processwire (3.0.1xx)

The gifs etc were very big, memory limit was 128M I think. I can't tell you the exact size because I told the person editing the page to make them (much) smaller and reupload. Of course, I can increase the memory and decrease the filesize but the problem was more about  being unable to get back into the page without uninstalling the module

Share this post


Link to post
Share on other sites
1 minute ago, cst989 said:

but the problem was more about  being unable to get back into the page without uninstalling the module

Instead of that, you can delete the imagefile. Then the frontend page and the admin page will load again.

To prevent this in the future, you may configure a setting for max filesize in those imagefields for uploads. (NOTE: not max dimensions, but max filesize and set it do be handled on clientside, not serverside)

I think there is a module available for this max-filesize-setting, but can't remember it's name. (ping: @Robin S do you have created one with this feature?)

Share this post


Link to post
Share on other sites
18 minutes ago, horst said:

ping: @Robin S do you have created one with this feature?

No, but I posted a hook for using the hidden JS max filesize validation for File fields:

I'm not sure if this validation is used for Image fields.

Another hook that could be used to check the filesize after an image is uploaded:

$wire->addHookBefore('InputfieldImage::fileAdded', function(HookEvent $event) {
	/* @var Pageimage $image */
	$image = $event->arguments(0);
	$max_filesize = 150000;
	if($image->filesize > $max_filesize) {
		throw new WireException("Image $image->basename is $image->filesize bytes which exceeds the maximum of $max_filesize bytes.");
	}
});

maxfilesize.gif.384e57fcc41ac500ff02d7936805e19e.gif

  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By gebeer
      I am happy to present my new fieldtype FieldtypeImageFromPage. It is made up of 2 modules:
      Fieldtype Image Reference From Another Page is a Fieldtype that stores a reference to a single image from another page. The image can be selected with the associated Inputfield.
      Inputfield Select Image From Page is an Inputfield to select a single image from images on a predefined page and it's children.
      And there also is a helper module that takes care of cleanup tasks.
      This module evolved out of a discussion about my other Module FieldtypeImagePicker.  It caters for use cases where a set of images is being reused multiple times across a site. With this fieldtype these images can be administered through a chosen page. All images uploaded to that page will be available in the inputfield.
      When to use ?
      Let editors choose an image from a set of images that is being used site-wide. Ideal for images that are being re-used across the site.
      Suited for images that are used on multiple pages throughout the site (e.g. icons).
      Other than the native ProcessWire images field, the images here are not stored per page. Only references to images on another page are stored. This has several advantages:
      one central place to organize images when images change, you only have to update them in one place. All references will be updated, too. (Provided the name of the image that has changed stays the same) Features
      Images can be manipulated like native ProcessWire images (resizing, cropping etc.) Image names are fully searchable through the API Accidental image deletion is prevented. When you want to delete an image from one of the pages that hold your site-wide images, the module searches all pages that use that image. If any page contains a reference to the image you are trying to delete, deletion will be prevented. You will get an error message to help you edit those pages and remove references there before you can finally delete the image. How to install and setup
      Download and install this module like any other modules in ProcessWire Create a page in the page tree that will hold your images. This page's template must have an images field Upload some images to the page you created in step 2 Create a new field. As type choose 'Image Reference From Another Page'. Save the field. In 'Details' Tab of the field choose the page you created in step 2 Click Save button Choose the images field name for the field that holds your images (on page template from step 2) Click Save button again Choose whether you want to include child pages of page from step 2 to supply images Add the field to any template You are now ready to use the field View of the inputfield on the page edit screen:

      View of the field settings

      The module can be installed from this github repo. Some more info in the README there, too.
      In my tests it was fairly stable. After receiving your valued feedback, I will eventually add it to the modules directory.
      My ideas for further improvement:
      - add ajax loading of thumbnails
      Happy to hear your feedback!
       
    • By gebeer
      Although the PW backend is really intuitive, ever so often my clients need some assistance. Be it they are not so tech savvy or they are not working in the backend often.
      For those cases it is nice to make some help videos available to editors. This is what this module does.
      ProcessHelpVideos Module
      A Process module to display help videos for the ProcessWire CMS. It can be used to make help videos (screencasts) available to content editors.
      This module adds a 'Help Videos" section to the ProcessWire backend. The help videos are accessible through an automatically created page in the Admin page tree. You can add your help videos as pages in the page tree. The module adds a hidden page to the page tree that acts as parent page for the help video pages. All necessary fields and templates will be installed automatically. If there are already a CKEditor field and/or a file field for mp4 files installed in the system, the module will use those. Otherwise it will create the necessary fields. Also the necessary templates for the parent help videos page and it's children are created on module install. The module installs a permission process-helpvideos. Every user role that should have access to the help video section, needs this permission. I use the help video approach on quite a few production sites. It is stable so far and well received by site owners/editors. Up until now I installed required fields, templates and pages manually and then added the module. Now I added all this logic to the install method of the module and it should be ready to share.
      The module and further description on how to use it is available on github: https://github.com/gebeer/ProcessHelpVideos
      If you like to give it a try, I am happy to receive your comments/suggestions here.
    • By Robin S
      A module created in response to the topic here:
      Page List Select Multiple Quickly
      Modifies PageListSelectMultiple to allow you to select multiple pages without the tree closing every time you select a page.
      The screencast says it all:

       
      https://github.com/Toutouwai/PageListSelectMultipleQuickly
      https://modules.processwire.com/modules/page-list-select-multiple-quickly/
    • By gebeer
      Hello all,
      sharing my new module FieldtypeImagePicker. It provides a configurable input field for choosing any type of image from a predefined folder.
      The need for it came up because a client had a custom SVG icon set and I wanted the editors to be able to choose an icon in the page editor.
      It can also be used to offer a choice of images that are used site-wide without having to upload them to individual pages.
      There are no image manipulation methods like with the native PW image field.
      Module and full description can be found on github https://github.com/gebeer/FieldtypeImagePicker
      Kudos to @Martijn Geerts. I used his module FieldTypeSelectFile as a base to build upon.
      Here's how the input field looks like in the page editor:

      Hope it can be of use to someone.
      If you like to give it a try, I'm happy to hear your comments or suggestions for improvement. Eventually this will go in the module directory soon, too.
    • By bernhard
      @Sergio asked about the pdf creation process in the showcase thread about my 360° feedback/survey tool and so I went ahead and set my little pdf helper module to public.
      Description from PW Weekly:
       
      Modules Directory: https://modules.processwire.com/modules/rock-pdf/
      Download & Docs: https://github.com/BernhardBaumrock/RockPDF
       
      You can combine it easily with RockReplacer: 
      See also a little showcase of the RockPdf module in this thread:
       
×
×
  • Create New...