Coder Social home page Coder Social logo

pngPath is not defined about electron-icns-ex HOT 12 CLOSED

bb-fat avatar bb-fat commented on August 20, 2024
pngPath is not defined

from electron-icns-ex.

Comments (12)

slavikator avatar slavikator commented on August 20, 2024 1

Thanks for the explanation. This is my first Electron project, definitely something wrong with my understanding here. ))

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

pngPath is the destination path where the converted icns file is stored, which is defined by yourself.

from electron-icns-ex.

slavikator avatar slavikator commented on August 20, 2024

That's what I understood. So, it seems nothing wrong with the code and still, I get an error.

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

try replace parseIcnsToPNG(localIconPath, pngPath); to icns.parseIcnsToPNG(localIconPath, pngPath);

from electron-icns-ex.

slavikator avatar slavikator commented on August 20, 2024

Yes, I have done this before - the same error.

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

Can you show me more complete code and error? And did you try icns.parseIcnsToBase64?

from electron-icns-ex.

slavikator avatar slavikator commented on August 20, 2024

This is basically what is related to showing the image.

renderer.js

    const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
    const icns = require('electron-icns-ex');
    icns.parseIcnsToPNG(localIconPath, pngPath);
    const img = document.querySelector("#localIcon");
    img.src = pngPath;

index.html

          <div>
            <img id="localIcon" src="">
          </div>

log
image

P.S.
The image displays if I replace the img.src = pngPath to img.src = "pathtoimage.png", where pathtoimage.png is a test image saved locally.

from electron-icns-ex.

slavikator avatar slavikator commented on August 20, 2024

Didn't figure out how to use the icns.parseIcnsToBase64

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

There are two problems here.

  1. This module is a native module, and you can not use native module in the renderer process. You should write these code in main process and pass the result to renderer process via IPC channel.
  2. There is something wrong with your understanding here, maybe it's because my README is relatively simple and doesn't make it clear. The corrected code is as follows.
// in main process
const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
const icns = require('electron-icns-ex');
const pngPath = '/tmp/test.png'; // To save the png file, you need to specify the path manually.
icns.parseIcnsToPNG(localIconPath, pngPath);

// in renderer process
const img = document.querySelector("#localIcon");
img.src = pngPath;

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

I'll close this issue, if there is still a problem you can reopen it.

from electron-icns-ex.

slavikator avatar slavikator commented on August 20, 2024

const pngPath = '/tmp/test.png'; // To save the png file, you need to specify the path manually.
I need to avoid saving the file.
It seems the icns.parseIcnsToBase64 must be used instead.

Will this be correct then?

// in main process

const localIconPath = ddPath + "/Contents/Resources/" + CFBundleName + ".icns";
const icns = require('electron-icns-ex');
const base64 = icns.parseIcnsToBase64(localIconPath);

// in renderer process

const img = document.querySelector("#localIcon");
img.src = base64;

from electron-icns-ex.

BB-fat avatar BB-fat commented on August 20, 2024

That's right.

from electron-icns-ex.

Related Issues (2)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.