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)
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.
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.
To solve the problem, we have two options:
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]
コメントを追加