GIF 製作
用多張圖片幀或精靈圖製作 GIF,並調整 FPS、尺寸、預覽與下載。
GIF動畫
開啟工具免費圖片工具箱
將 PNG 幀合併為精靈圖,並調整像素間距、輸出中繼資料與動畫預覽。
無需註冊或付款即可使用,檔案會盡可能在瀏覽器中處理。
上傳圖片
點擊或拖放檔案到這裡
大型圖片可能會讓瀏覽器變慢。
精靈圖會使用瀏覽器 canvas 產生。過大的 canvas 可能碰到瀏覽器限制。
預估 canvas 尺寸: 上傳後自動計算 / 欄數: 4 / 列數: -
幀間距是每個幀之間的距離。如果要讓遊戲引擎容易自動切割,可以使用 0px;如果想讓精靈圖更容易檢查,建議使用 2~4px。
建議使用 px 作為單位。精靈圖需要精確的像素座標,因此 px 比 %、rem 等相對單位更適合。
列可用於下、上、左、右等方向動畫,但實際意義可依你的圖片配置自由解讀。
const image = new Image();
image.src = "spritesheet.png";
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");
ctx.imageSmoothingEnabled = false;
const frameWidth = 32;
const frameHeight = 32;
const columns = 4;
const frameSpacing = 2;
const cellPadding = 0;
const outerMargin = 0;
let frame = 0;
let last = 0;
function drawFrame(index) {
const col = index % columns;
const row = Math.floor(index / columns);
const sx = outerMargin + col * (frameWidth + cellPadding * 2 + frameSpacing) + cellPadding;
const sy = outerMargin + row * (frameHeight + cellPadding * 2 + frameSpacing) + cellPadding;
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.drawImage(image, sx, sy, frameWidth, frameHeight, 0, 0, frameWidth, frameHeight);
}
function loop(time) {
if (time - last > 125) {
drawFrame(frame);
frame = (frame + 1) % 1;
last = time;
}
requestAnimationFrame(loop);
}
image.onload = () => requestAnimationFrame(loop);CSS steps 範例最適合幀間距為 0px 的單列精靈圖。多列或有間距時,JavaScript 方式更有彈性。
.sprite {
width: 32px;
height: 32px;
background-image: url("spritesheet.png");
animation: play 0.13s steps(1) infinite;
}
@keyframes play {
from { background-position: 0 0; }
to { background-position: -32px 0; }
}如果想將幀動畫儲存為 GIF,可以使用 GIF 製作工具。
開啟 GIF 製作工具檔案會盡可能在瀏覽器中處理,且不會儲存在伺服器上。
此工具著重於遊戲素材用精靈圖製作。若要將幀動畫儲存為 GIF,請使用 GIF 製作工具。