• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Getting Images with cp.imagesJSONCache

New Here ,
May 06, 2022 May 06, 2022

Copy link to clipboard

Copied

 

I’m in the process of making a widget for captivate. I have been having issues with images not being accessible with my javascript, sometimes. The issue that I have been able to track down that a line of code seems to only retrieve 4 of the img json files that captivate generators.

 

I am getting the json files with the images with: ‘window.parent.cp.imagesJSONCache

The result I get when I console.log is

Brat5E4F_0-1651865924826.png

 

 

Looking through this object, the image that I need does not exist in these json files that were retrieved.

Brat5E4F_1-1651865924836.png

 

 

I can use ‘window.parent.cp.imageToJSONPathMap’  to pull information of which json file the image lives in. In my screenshots I need the img2.json which isn’t loaded with the JSONCache.  

 

Brat5E4F_2-1651865924842.png

 

I don’t know if there is a way to get in ALL the json files or grab the one I need with javascript  if it doesn't load. Or if there should be another route I should be taking to get these images?

 

Views

135

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2024 Aug 16, 2024

Copy link to clipboard

Copied

LATEST

Not 100% production ready or tested, but the basics work

 

                        const imageObj = cp.model.data[ feedbackData.lb + 'c' ];
                        const imgPath = imageObj?.imgf?.img?.ip;
                        if( imgPath ){
                            const jsonPath = cp.imageToJSONPathMap[ imgPath ];
                            const file = 'dr/'+ jsonPath;
                            // Extract the part of the string containing the index
                            const startIndex = file.indexOf("img") + 3;
                            const endIndex = file.indexOf(".json");
                            const indexStr = file.substring(startIndex, endIndex);
                            // Convert the extracted string to a number
                            const index = parseInt(indexStr, 10);
                            var script = dlcCreate({type:'script',  classes: '', attrs:{}, parent: dlc.headEl});
                            script.type = 'text/javascript';
                            script.src = file;
                            
                            script.onload = function() {
                              console.log('loaded');
                              const base64Image = cp[ 'imagesJSONCache00' + index ][ imgPath ];
                                const img = new Image();
                                // Set the src attribute to the Base64 string
                                img.src = "data:image/png;base64," + base64Image;
                                dlc.html.appendChild(img);
                            };

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources