PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label graphicsmagick. Show all posts
Showing posts with label graphicsmagick. Show all posts

Tuesday, July 26, 2022

[FIXED] How to crop to equally sized tiles using GraphicsMagick?

 July 26, 2022     crop, graphicsmagick, imagemagick, tiles     No comments   

Issue

Is it possible to crop equally sized tiles using GraphicsMagick, similar to ImageMagick's crop "@" modifier?

convert montage.gif -crop 5x1@ +repage +adjoin montage_%d.gif

Is it possible to use GraphicsMagick's crop "%" modifier, if the height of the image dimensions are constant?

Sample image directly from the ImageMagick manual:

https://legacy.imagemagick.org/Usage/crop/montage.gif

I would like to divide the sample image into 5 equal tiles, as shown in the ImageMagick manual.


Solution

You can maybe let bash do the work for you instead:

# Get height and width of image
read h w < <(gm identify -format "%h %w" montage.gif)  

# Crop into 5 full-height, equal width parts
gm convert montage.gif -crop $((w/5))x$h +adjoin result%d.jpg

You can maybe let shell do the work for you instead:

gm convert montage.gif -trim -gravity center trimmed.gif;

d=$(gm identify -format "%h %w" trimmed.gif); h=$(echo $d | grep -ioE "([0-9]+\s)"); w=$(echo $d | grep -ioE "(\s[0-9]+)"); echo $h; echo $w;

gm convert trimmed.gif -gravity center -crop $((w/5))x$h +adjoin result%d.jpg


Answered By - Mark Setchell
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 17, 2022

[FIXED] How to fix .gif with corrupted alpha channel (stuck pixels) collected with Graphicsmagick?

 July 17, 2022     encode, ffmpeg, gif, graphics, graphicsmagick     No comments   

Issue

I want to convert an .avi with alpha channel into a .gif.
Firstly, I use

ffmpeg -i source.avi -vf scale=720:-1:flags=lanczos,fps=10 frames/ffout%03d.png

to convert .avi to sequence of .png's with aplha channel.
Then, I use

gm convert -loop 0 frames/ffout*.png output.gif

to collect a .gif.
But it seems that pixels of the output.gif just get stuck when something opaque is rendered on top of the transparent areas.

Here's an example:

img

As you can see the hearts and explosions do not get derendered.

P.S. FFMPEG output (collection on .png's) is fine.


Solution

I do not use Graphicsmagick but your GIF has image disposal mode 0 (no animation). You should use disposal mode 2 (clear with background) or 3 (restore previous image) both works for your GIF. The disposal is present in gfx extension of each frame in the Packed value.

So if you can try to configure encoder to use disposal = 2 or 3 or write script that direct stream copy your GIF and change the Packed value of gfx extension chunk frame by frame. Similar to this:

  • GIF Image getting distorted on interlacing

If you need help with the script then take a look at:

  • How to find where does Image Block start in GIF images?
  • Decode data bytes of GIF87a raster data stream

When I tried this (C++ script) on your GIF using disposal 2 I got this result:

disposal=2

The disposal is changed in C++ like this:

struct __gfxext
    {
    BYTE Introducer;        /* Extension Introducer (always 21h) */
    BYTE Label;             /* Graphic Control Label (always F9h) */
    BYTE BlockSize;         /* Size of remaining fields (always 04h) */
    BYTE Packed;            /* Method of graphics disposal to use */
    WORD DelayTime;         /* Hundredths of seconds to wait    */
    BYTE ColorIndex;        /* Transparent Color Index */
    BYTE Terminator;        /* Block Terminator (always 0) */
    __gfxext(){}; __gfxext(__gfxext& a){ *this=a; }; ~__gfxext(){}; __gfxext* operator = (const __gfxext *a) { *this=*a; return this; }; /*__gfxext* operator = (const __gfxext &a) { ...copy... return this; };*/
    };

__gfxext p;
p.Packed&=255-(7<<2);   // clear old disposal and leave the rest as is
p.Packed|=     2<<2;    // set new disposal=2 (the first 2 is disposal , the <<2 just shifts it to the correct position in Packed)

It is a good idea to leave other bits of Packed as are because no one knows what could be encoded in there in time ...



Answered By - Spektre
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, May 11, 2022

[FIXED] How can I know the jpeg quality of the read image using graphicsmagick

 May 11, 2022     c++, graphicsmagick, image     No comments   

Issue

When I read a jpeg image using Magick::readImages(...) function. How can I know the estimated jpeg quality of the image? I know how to set the quality when I wanna write the image, but it is not relevant to the quality of the original image, so for example: when I read a jpeg image that its quality is 80% and I write it using 90% quality I will get a bigger image than the original one, since the 90% is not 90% out of the original 80%. How can I know the jpeg quality of the read image?


Solution

This is impossible, period. The JPEG quality settings is just a number that is passed to the encoder and affects how the encoder treats the data.

It's not even percentage of anything - it is just some setting that affects how aggressively the encoder manipulates and transforms data. Wherever you see the percent sign near JPEG quality just ignore it - it's meaningless there.

So regardless of the encoder it is impossible to find which JPEG quality settings value the enocder used to produce this very image. The only way would be to obtain the original and try all reasonably possible setting values until you hit the same result.



Answered By - sharptooth
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing