How to center images in gif using convert from imagamagick?

PziStiv Chanell

My goal is to create gif image from jpg which I will rotate on angle A with delay D imagemagick. So, i've got this code:

for (( i=0; i < 360; i+=$a )) do
   name=%(printf "%03d" $i)
   convert $image -rotate $i "temp/$name.jpg"
done
convert -delay $d "temp/*.jpg" out.gif

The problem is that images in out.gif is not centered. How can i center them? (image should be rotated relative to the center)

Socowi

The problem is that images in out.gif is not centered.

It just seems that way when you look at the final gif. However, the image already rotates around its center. Example: I have the image 1.png and rotate it in steps of 15°.

convert 1.png -rotate 15 2.png
convert 1.png -rotate 30 3.png
convert 1.png -rotate 45 4.png

Now let's have a look at the images 1-4.

rotated images

As we can see, the image rotates around its center, but the image dimension changes.

When we convert those four images into one gif animation, we have to set a fixed dimension for the whole animation and a position of each frame on the canvas. Without giving further information, ImageMagick uses the first frame's dimension as the dimension of the animation and places each frame at the top left. Since the first frame (rotation 0°) is the smallest, the other frames get cropped. The following illustration shows what will get cropped.

animation

To solve the problem, we have two options:

  1. When creating the animation, center each frame.
  2. When rotating, crop the result such that all frames have the same size.

I would go with 2. ImageMagick has the operator -distort SRT <ANGLE> which rotates and crops in one step. Using this operator will also look smoother in animations, see here. Replace your -rotate $i with -distort SRT $i.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

how to center MRI images

分類Dev

How to compress images and convert them into progressive images using cloud code?

分類Dev

How to center a group of images in HTML/CSS?

分類Dev

How to vertically and horizontally center two images inside a div on a responsive page

分類Dev

How to convert a .pdf file into a folder of images?

分類Dev

How to convert images color space in Keras?

分類Dev

How to convert from wkt to wkb with spesifc srid (using shapely)

分類Dev

How can you write an algorithm to properly fill a circle using lines from the center?

分類Dev

Remove transparent white background from gif image using glide?

分類Dev

How to create ImageView center on storyboard using iOS?

分類Dev

How to center vertically an image using flex box?

分類Dev

How do I create an animated gif in Python using Wand?

分類Dev

How to remove Media Center from Windows 8

分類Dev

How to scale a shape from its center as origin?

分類Dev

How to retrieve all images from sql to the html DIV tag using php?

分類Dev

Convert images to png using image magick and not changing its name

分類Dev

Using gganimate to export gif

分類Dev

What viewers can play gif animated images?

分類Dev

How to add text to multiple images using Python

分類Dev

How to upload multiple images into a database using laravel?

分類Dev

How to Dynamically Load Images Using UIScrollview

分類Dev

How to create an image using images with FFMPEG?

分類Dev

Java: How to Scrape Images from Amazon with Selenium?

分類Dev

How to pick multiple images from device?

分類Dev

How to display images fetching from server in ARCore?

分類Dev

How to parse images in json from html page

分類Dev

How to convert from list to ellipsis?

分類Dev

How to convert Avro GenericRecord to a valid Json using while coverting timestamp fields from milliseconds to datetime?

分類Dev

how do I convert an array from a form into a database using PHP and Mysql

Related 関連記事

  1. 1

    how to center MRI images

  2. 2

    How to compress images and convert them into progressive images using cloud code?

  3. 3

    How to center a group of images in HTML/CSS?

  4. 4

    How to vertically and horizontally center two images inside a div on a responsive page

  5. 5

    How to convert a .pdf file into a folder of images?

  6. 6

    How to convert images color space in Keras?

  7. 7

    How to convert from wkt to wkb with spesifc srid (using shapely)

  8. 8

    How can you write an algorithm to properly fill a circle using lines from the center?

  9. 9

    Remove transparent white background from gif image using glide?

  10. 10

    How to create ImageView center on storyboard using iOS?

  11. 11

    How to center vertically an image using flex box?

  12. 12

    How do I create an animated gif in Python using Wand?

  13. 13

    How to remove Media Center from Windows 8

  14. 14

    How to scale a shape from its center as origin?

  15. 15

    How to retrieve all images from sql to the html DIV tag using php?

  16. 16

    Convert images to png using image magick and not changing its name

  17. 17

    Using gganimate to export gif

  18. 18

    What viewers can play gif animated images?

  19. 19

    How to add text to multiple images using Python

  20. 20

    How to upload multiple images into a database using laravel?

  21. 21

    How to Dynamically Load Images Using UIScrollview

  22. 22

    How to create an image using images with FFMPEG?

  23. 23

    Java: How to Scrape Images from Amazon with Selenium?

  24. 24

    How to pick multiple images from device?

  25. 25

    How to display images fetching from server in ARCore?

  26. 26

    How to parse images in json from html page

  27. 27

    How to convert from list to ellipsis?

  28. 28

    How to convert Avro GenericRecord to a valid Json using while coverting timestamp fields from milliseconds to datetime?

  29. 29

    how do I convert an array from a form into a database using PHP and Mysql

ホットタグ

アーカイブ