trim +repage animated gif issue
trim +repage animated gif issue
hello
I'm having an issue trying to trim an animated gif to remove the "boring bits" as you say in your docs
when I do trim without any other option, the gif output still has the boring bits around
when I do with repage it does remove the boring bits however, the result can be a mess and completely misaligned
from what I understand the position of every frame is lost
so my question is : is there a way to automatically trim (without human eye) and preserve the position/alignment or the animated gif
I'm having an issue trying to trim an animated gif to remove the "boring bits" as you say in your docs
when I do trim without any other option, the gif output still has the boring bits around
when I do with repage it does remove the boring bits however, the result can be a mess and completely misaligned
from what I understand the position of every frame is lost
so my question is : is there a way to automatically trim (without human eye) and preserve the position/alignment or the animated gif
Last edited by coloring on 2017-01-06T09:54:28-07:00, edited 5 times in total.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: trim +repage animated gif issue
My "Fractal noise animations" page has a script, frTrim.bat, for this task. If all your frames can fit into memory at the same time, the script can be simplified.
snibgo's IM pages: im.snibgo.com
Re: trim +repage animated gif issue
interesting thank you, but .bat is windows script am I wrong?
I use imagemagick on linux unfortunately
could you please provide a linux script ? thank you
I use imagemagick on linux unfortunately
could you please provide a linux script ? thank you
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: trim +repage animated gif issue
What version IM are you using? If v7, and your GIFs are small, it can probably be done in a single convert. (Append frames vertically to get the horizontal trim, and horizontally to get the vertical trim.)
snibgo's IM pages: im.snibgo.com
Re: trim +repage animated gif issue
I use IM 6 from the jessie repository
unfortunately it would be risky to update manually to v7 as I would no longer be synched with the repository and security updates, not an option for production environments
do you mean IM v7 can do it and IM v6 can not?
unfortunately it would be risky to update manually to v7 as I would no longer be synched with the repository and security updates, not an option for production environments
do you mean IM v7 can do it and IM v6 can not?
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: trim +repage animated gif issue
This trimming can be done pretty easily using either IM6 or IM7. It's just that ImageMagick 7 can often reduce a process like this to a single command. Using IM 6.7.7 from a bash shell prompt I can do something like this to accomplish your task...coloring wrote:do you mean IM v7 can do it and IM v6 can not?
Code: Select all
inimage=YZu6yZx.gif
trimmer=`convert $inimage -coalesce -flatten -format %@ info:`
convert $inimage -coalesce -crop $trimmer +repage result.gif
Using ImageMagick 7 you'd be able to obtain the trimming specs and trim the image all in one command, calculating the dimensions and offsets and applying those to the crop directly instead of putting those specs in a shell variable as an intermediate step. I don't have IM7 installed on a *nix machine, but using IM 7.0.4 from a Windows CMD prompt, a command like this would do it...
Code: Select all
set INIMAGE=YZu6yZx.gif
magick %INIMAGE% -coalesce ^
( -clone 0--1 -flatten -set option:trimmer %@ +delete ) -crop %[trimmer] +repage result_IM7.gif
Re: trim +repage animated gif issue
After using this fix, I noticed a weird issue where image that is supposed to be trimmed, ends being even larger than the original
here's an example
https://www.sendspace.com/file/dj05ql
the source is 304x411 and the result is 374x415
do you know what is causing this issue? thank you
here's an example
https://www.sendspace.com/file/dj05ql
the source is 304x411 and the result is 374x415
do you know what is causing this issue? thank you
Re: trim +repage animated gif issue
Your injput.gif contains offsets. "magick identify -verbose input.gif" says, for the first frame, "Page geometry: 374x416+70+4"
Re: trim +repage animated gif issue
Thank you but I have no idea what is an offset and how I do fix this issue. Any idea?
Is there a way to make imagemagick ignore this offset?
Is there a way to make imagemagick ignore this offset?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: trim +repage animated gif issue
Add +repage right after reading the input image to remove the virtual canvas with its offsets.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: trim +repage animated gif issue
As fmw42 mentioned, you may just need to reset the paging information with "+repage". You might have to put it after the "-coalesce" operation. That's where the GIF gets broken into separate frames while still keeping their relative +W+H locations in the viewport. If the "+repage" is before the "-coalesce", the frames may lose the paging information that keeps them +W+H aligned from one to the next.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: trim +repage animated gif issue
Sorry about that. Geemack is probably right.
Re: trim +repage animated gif issue
I just tried replacing the second command like this
trimmer=`convert $inimage -coalesce -flatten -format %@ info:`
>
trimmer=`convert $inimage -coalesce +repage -flatten -format %@ info:`
but it makes no difference
if +repage is before -coalesce it returns the correct size, but you said I would loose the paging information
so what should I do
trimmer=`convert $inimage -coalesce -flatten -format %@ info:`
>
trimmer=`convert $inimage -coalesce +repage -flatten -format %@ info:`
but it makes no difference
if +repage is before -coalesce it returns the correct size, but you said I would loose the paging information
so what should I do
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: trim +repage animated gif issue
The frames in your GIF are different sizes, because that is how GIF normally works. Eg frame [0] is 304x411 but frame [1] is 308x413. They all sit on a canvas that is 374x416. What is the problem? What do you want to change?
snibgo's IM pages: im.snibgo.com