chenqingspring / vue-lottie

Render After Effects animations on Vue based on Bodymovin
MIT License
1.31k stars 281 forks source link

Animation with images is not working #14

Open Nojugames opened 6 years ago

Nojugames commented 6 years ago

If there is an animation that uses images then the images don't load. The SVG animations still work but the images from the /images folder just don't show up.

bagada commented 6 years ago

i solved this adding each image a require word like this (in my animation.json)

"assets": [{ "id": "image_0", "w": 72, "h": 117, "u": "images/", "p": 'img_0.png', "e": 0 }, { "id": "image_1", "w": 57, "h": 69, "u": "images/", "p": 'img_1.png', "e": 0 }, {

To

"assets": [{ "id": "image_0", "w": 72, "h": 117, "u": "", "p": require('@/assets/animation/images/img_0.png'), "e": 0 }, { "id": "image_1", "w": 57, "h": 69, "u": "", "p": require('@/assets/animation/images/img_1.png'), "e": 0 }, {

dreamstyle commented 5 years ago

If you're using Vue CLI 3, you should put your image folder in public instead of src. It works for me.

MrMarik commented 5 years ago

i solved this adding each image a require word like this (in my animation.json)

"assets": [{ "id": "image_0", "w": 72, "h": 117, "u": "images/", "p": 'img_0.png', "e": 0 }, { "id": "image_1", "w": 57, "h": 69, "u": "images/", "p": 'img_1.png', "e": 0 }, {

To

"assets": [{ "id": "image_0", "w": 72, "h": 117, "u": "", "p": require('@/assets/animation/images/img_0.png'), "e": 0 }, { "id": "image_1", "w": 57, "h": 69, "u": "", "p": require('@/assets/animation/images/img_1.png'), "e": 0 }, {

i got a JSON paser faild error when write as yours

dankotov commented 4 years ago

I solved this by tweaking the Bodymovin settings inside After Effects. Under your composition settings in Bodymovin extension you can navigate to Assets settings and choose "Include in json".

Screen Shot 2020-01-01 at 7 55 04 PM

This will provide the json file not a path to your image but an actual code of it.

Screen Shot 2020-01-01 at 7 55 33 PM

Sorry for such a late answer, just stumbled across Bodymovin and this issue. Hope it helps though :)

tobiasfamos commented 3 years ago

I am having the same problem. Neither including the assets in the JSON, nor putting the images folder in the public folder worked. Any ideas?

edgonzalez24 commented 2 years ago

Hi guys! I had this same issue but I could fix it, transform the JSON file to a JS file using an export const, and set values in assets "p" (path) key using required function. Example:

// Lottie Files (JS)
export const animationData = {
  "v": "5.7.4",
  "fr": 25,
  "ip": 0,
  "op": 140,
  "w": 385,
  "h": 394,
  "nm": "loading",
  "ddd": 0,
  "assets": [
    {
      "id": "image_0",
      "w": 79,
      "h": 84,
      "u": "",
      "p": require('./images/img_0.png'), // I used require to find assets
      "e": 0
    }
   ]
}

 //(Component)
 import { animationData } from '@/assets/file-lottie'

<lottie
   class="lottie"
   :options="{animationData}"
   v-on:animCreated="handleAnimation"
 />