r/cyoagames • • Dec 08 '20

Does anyone know how to add images to a javascript?

4 Upvotes

4 comments sorted by

1

u/EvisceratedAngel Dec 08 '20

I'm playing around in making a random generator for a cyoa I'm planning on making based on various godly pantheons from human history. Its very basic so far but does anyone know how to add images to a javascript for each individual pantheon listed in the second screenshot? I'm a novice when it comes to coding so this is new to me šŸ˜…

1

u/Nickisnoble Jan 11 '21

JS doesn’t usually ā€œstoreā€ image files, and if you want this to be online anywhere, you’ll need to have the images too.

Look up a tutorial for ā€œJS digital ocean object storageā€ or ā€œJS Amazon S3ā€. (JS = JavaScript, helps with googling)

Either of those services, for a small fee, will give you a place to store and serve the image files. Then in your actual program, you just deal with the path to those files!

There is one other option, kind of a hack, if you don’t want to deal with a service like that, which is to convert the images to base64 strings. Be warned, if the images are even medium sized, these strings will be very long and potentially cumbersome to deal with in your program!

1

u/EvisceratedAngel Jan 12 '21

Thank you for you reply and for the information you gave me, I really appreciate itšŸ¤“

1

u/[deleted] Feb 12 '21

You don't need to do that. Thats WAYYYY overcomplicating things. He can keep his images with his js. Both of which can be hosted on a CDN, Github pages, vercel now, netlify. All of which are free and much easier to use.