Convert an image file in Base64 or another string value

Hello

I need to read the content an image file () JPEG, PNG, TIFF) and convert this file to Base64 string.

Anyone know if you can do these things the Javascript in InDesign?

Thank you any help

EDIT: I forgot to add that I know my image path on filesystem, it lies within the my file system. I get this way thanks to InDesign...

Hello

You need:

var file = new File (pathFile);

then

   file.encoding = "BINARY";

Ok. Let's try this:

var base64Encode = function(/*str*/s)
//--------------------------------------
 {
    var ALPHA = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

    var n = s.length,
        a = [], z = 0, c = 0,
        b, b0, b1, b2;

    while( c < n )
        {
        b0 = s.charCodeAt(c++);
        b1 = s.charCodeAt(c++);
        b2 = s.charCodeAt(c++);

        var b = (b0 << 16) + ((b1 || 0) << 8) + (b2 || 0);

        a[z++] = ALPHA.charAt((b & (63 << 18)) >> 18);
        a[z++] = ALPHA.charAt((b & (63 << 12)) >> 12);
        a[z++] = ALPHA.charAt(isNaN(b1) ? 64 : ((b & (63 << 6)) >> 6));
        a[z++] = ALPHA.charAt(isNaN(b2) ? 64 : (b & 63));
        }

    s = a.join('');
    a.length = 0;
    a = null;
    return s;
};

var fileToBase64 = function(/*File|str*/f)
//--------------------------------------
{
    var s = null;

    if( f && (f = new File(f)) && (f.encoding='BINARY') && f.open('r') )
        {
        s = f.read();
        f.close();
        }

    return s && base64Encode(s);
};

// Client code
// ---
var b64 = fileToBase64("my/path/to/image.jpg");

@+

Marc

Tags: InDesign

Similar Questions

  • save an image in an image file and reloaded on another computer for the image processing

    Hello

    Can I save the image to an image file and then reload the file on another computer for the image processing? What type of image format should I save for it? Is there any loss of image if I do this? The machine with the camera sits in our lab, and I want to test the software on my own computer image processing. So can someone give some good ideas on this. Thank you

    Jane

    I assume you have the module development VDM and vision acquisition software going TO on your computer.

    So just use playback IMAQ and IMAQ save functions. BMP, png are good for losless save unlike jpg and jpeg2000.

    Hope this helps

  • Convert binary (Blob) image file to string base64 on PlayBook?

    I need to download image files of the PlayBook to a Web server.

    When you use BB10, it's pretty easy, basically just using reader.readAsBinaryString (file) to get the file as a string, encode in Base64, then send it with xml.send(fileData). Which works very well with my Z10.

    But the PlayBook seems to have its own file system that does not work the same as handling BB10. I can read the file very well with blackberry.io.file.readFile (path, pbOpenImageFile)image, but it gives me just the Blob. How can I get this Blob converted a Base64 string for sending with xml.send (fileData)?

    blackberry.utils.blobToString (blobData) doesn't seem to work, at least not with my image data (works very well with my text files however). He also apparently has a size limit that could be a problem with the images anyway.

    Is it possible to get that converted to a string in Base64 Blob?

    I have it.

    Take the idea of here something like:

    var can = document.getElementById ('canvas');
    var can.getContext ('2d') = CTX;
    var img = document.getElementById ('tweetpic');
    ctx.drawImage (img, 0, 0);
    var b64Text = can.toDataURL ();
    b64Text = b64Text.replace ("data : image/png;") Base64,', ");
    var fileData = b64Text;

    And then xml.send (fileData); as usual

  • How to remove image files i've got duplicates when it says I can't do it because the file is open in another program? What does that mean?

    How to remove image files i've got duplicates when it says I can't do that because the folder is open in another program? What does that mean?

    Hello

    • What version of Windows are you using?
    • What were the changes made before the problem occurred?

    Follow the steps in this given link and check if that helps.

    Method 1: check out the link below and follow the steps

    Access the link for more information about the error you receive below:

    Why can't I delete a file or a folder?

    http://Windows.Microsoft.com/en-us/Windows7/why-cant-I-delete-a-file-or-folder

    Method 2: you can also try to remove the file getting mode without failure.

    Access the link below to learn more about Safe Mode:

    Start your computer in Mode safe:

    Method 3:
    Once you face this problem you can check in Manager tasks if there is an executed program attached to it.

    a. right-click on the taskbar and click Task Manager.
    b. in the Windows Task Manager window, go to 'Process' and check if there is no program associated with those files.


     
  • Try to remove a CD image file, get the error message "this action cannot be completed because the file is open in another program.

    I am trying to remove a file from CD image (.img) of my office

    When I try to put it in the bin I get the message

    "The action cannot be completed because the file is open in another program close the file, and then try again"

    First, I checked the obvious things like if the .img file was mounted in a virtual drive - it isn't so I then used LockHunter to find which application is using the file so I can close by the Task Manager.

    Unfortunately LockHunter told me that the file is used by 'System' - which cannot be closed through the TM.

    Any help?

    The problem is that the program that allows you to mount the image always uses the image.  In my case I used the magical disc. Go to the start menu find the magic disk or folder folder, there should be an option to uninstall the magic disc. I tried UN-installing conrtol add and remove programs but it wouldn't let me. You can also click on computer in Start menu and see if the file you want to remove is always mounted (appears as a CD image). In this case that you can click the eject disc hit.

  • How to change your settings to allow you to be able to place images and things outside of the artboard when you work? I have it on a single file and I opened another and the setting seems to have changed, but I can't find where to change it.

    How to change your settings to allow you to be able to place images and things outside of the artboard when you work? I have it on a single file and I opened another and the setting seems to have changed, but I can't find where to change it.

    I think that things are there, but just hidden.

    Try this:

    Make sure that your cursor is not in a text box, and then type a W.

  • I converted a PDF file to word.  Can I change the words, but not the page.  I can't change the margins. If I delete a picture of the page, space where the image is unusable.

    I converted a PDF file to word. Can I change the words, but not the page. I can't change the margins. If I delete a picture of the page, space where the image is unusable.  Can someone help me please? Gary

    Thank you, Gary!

    I appreciate your comments! Start with the basics: Getting Started with ExportPDF

    And here's a more complete step by step (that you already know, but I'll give the full game!):

    1. Sign in to your account on https://cloud.acrobat.com/exportpdf.
    2. Click on PDF files select export.
    3. Click on choose the files on my computer.
    4. Select one or more files and click on choose (you can select multiple files by pressing the Shift or Ctrl key when you click on the file).
    5. To convert to the: menu popup, select the output format you want (in this case, Microsoft Word).
    6. Let the language of the local menu Document configured to English (unless the PDF is in a foreign language).
    7. Click Export to Word. (The name of this button will vary depending on what format you selected in step 5)
    8. Once the file is converted, it will appear at the bottom of the window, listed under exported files.
    9. Hover your mouse over the thumbnail image of the file, and then click the icon that appears on the left side of the thumbnail to download the file in your downloads folder. (You can also click on the files tab in the upper part of the window to see a complete list of all converted files).
    10. Once you have downloaded the file, you can open it up in Word for editing.

    I hope this helps! If this isn't the case, you know where to find me!

    Best,

    Sara

  • I just purchased photos to shutterstock and they said, it will download as a .eps file. They said that I need vector editor like adobe illustrator to convert the image to the jpeg format. Could someone tell me how to proceed? This is all very alien to me.

    I just purchased photos to shutterstock and they said, it will download a .eps file. They said that I need vector editor like adobe illustrator to convert the image to the jpeg format. Could someone advise me on how to do this? This is all very alien to me.

    The chic Lady

    File > open to open your eps file

    File > export to export your image as a jpg.

    In the export dialog just below where you type the name of the file is a type of file, which is where you choose jpg.

    Whatever you do, do not delete the eps file. If you need to access the original you have.

    I recommend instead of jpg you choose psd, tiff, or png and jpg don't use that to share. Jpg is a lossy format, which means that whenever you modify the file and save it, degrades the quality of this file. The formats that I recommend are lossless formats, you can edit all you want that data is not being ignored, unless you choose to do so.

  • Files adjusted in Lightroom transfer to another computer if you need to reload the image files?

    I'm used to make adjustments in Camera RAW and copy the image files for use on multiple workstations.  In this case, my settings go with the image file.  If I do my settings using Lightroom and move the image files to another computer I'll lose these adjustments?  I wonder if I invest all my time adjustment using Lightroom and my computer freezes I'll lose these adjustments even if I am backing up my files to an external drive.

    You wrote: "if I do my settings using Lightroom and move the image files to another computer I lose these adaptations?

    Yes, you will lose them unless you save in xmp. You're saving xmp is pressing the CTRL / Cmd + letter "S" or

    (a) in the library Module, you'll > metadata > save metadata to file, or

    (b) in the develop Module, you'll > Photo > save metadata to file.

    Without , Lr writes the changes to the catalog only. And, if you transfer pictures without the catalog to another computer your changes will be lost on the second computer.

    By an xmp file will be created that stores changes. In the case of a DNG format changes are not written in Xmp, but in the file header - same effect.

    Note, however, that not everything can be stored in xmp files. For example, collections, stacking are stored in the catalog only.

    This is probably because the record to xmp has been created to allow adjustment of Lr can be accessed in other Adobe products (for example, bridge). Naturally, only those "features" should be written in xmp that the other program can display.

    WW

  • Why converts the images into a text file?

    I found that when I opened some art work that I have done in Illustrator CS4 work seems itself have converted into text files.

    Could someone tell me why this is happening. I seem to have lost the work which took many hours. I'm puzzled.

    Grateful for any advice.

    Kind regards.

    What gives you the impression that they are text files? The original format of the files was Postscript, a text format, but who died with AI9. Here is the PDF format.

  • Sonic RecordNow is able to burn the .iso Image files?

    I can't believe this. I might be Toshiba Satellite L20 205 is Record now Version 7.31 basic Sonic and has no facility for burning image (ISO format) on my CD/DVD files, unless and and util I move to Deluxe v7.3 for an additional price of $30.

    If this can be true? Save and burn disc button images takes me directly to the upgrade link on the Internet.
    This is the first time I came across an OEM bundled, disc burning trying to strip me for a simple job like burning the .iso files software?
    Am I missing something?

    Hello

    I don t use the sound recording now to make an iso file because I m user of Nero.
    I love this program. But back to Sonic.
    As much as I know Sonic doesn't supports this option. It doesn t create iso files.
    You can use it to create audio CDs from files on your HARD drive, convert audio CDs to MP3, create a Toshiba CD-ROM, CD copy, etc.

    If you want to create iso files, you must use another application like Nero

  • Open / convert .cwk drawing file into something else than Clarisworks

    Hello

    I have a problem and can't seem to find a solution.

    I have over 2000 + cards of Member (with images) stored in Clarisworks (.cwk) drawing files. Each file contains 10 cards of members with a photo that could be printed on paper card and laminate to make a membership card. so I have more than 200 of these drawing .cwk files.

    I need to be able to open these .cwk files in another program or convert them to another program that is not interrupted so that I can entrust the task of taking every photo, cropping and at a savings. JPG file with the dimensions of the specific pixels.

    I can't currently entrust this task as no one can open a .cwk file...

    Does anyone know how to open these drawing .cwk files in another program or convert them?  I found ways to open documents to simple text but nothing that can open files of drawing .cwk with embedded images.

    I also have access to an old Mac with the program of Clarisworks to open these files... Is it possible to convert it into a usable format more updated using this program?

    See you soon,.

    Duff

    I have something to play with, but I can suggest that if you have a computer OS x can open AppleWorks, you probably can click on the picture, copy it and open preview and place n command to create a new file of the image in the Clipboard, and then save it in a file with the name of the person.

    Preview will have the added benefit of saving to any size compatible format and file you want.

    A good workflow would be to create an empty (white) image in the right size, the resolution format and file preview and paste it into that. You should get the handles on the image to be able to resize to the borders of files. And then do a record under. Organize a list of parallel text of the names of all card holders, so you can save typing (and errors) to copy and paste into the names of image files.

    There may be other solutions you can think of that work better in practice once you have made a few.

    Peter

  • How can I change the type of image file to download on a site like walmart or walgreens for printing?

    How can I change the type of image file to download on a site like walmart or walgreens for printing?

    In general, they will accept the image in the format, that it was taken (if it was taken by the majority of cameras or cell phones).  But if so, you have a few options.

    The most simple and integrated solution is Microsoft Paint.  Yes it is from the 1980s, but it still works and changes of a good job for a time.  Just to right click on the photo file, choose open with and choose paint.  Then go to file > save as and save this return as the file type you want it to be (like PNG or BMP or JPG, quality declining in the JPG option).

    If you need more options like changing the quality he uses during conversion, another free option (of the very very many) is Paint.NET, an open source free image editing program. http://www.dotPDN.com/downloads/PDN.html

    There are also programs that can do it in bulk, so you can highlight 300 photos and do convert them all at once.  You can do this for free or with tools like Photoshop.

  • How to open or convert the .avi file on old mac running OS.10.6.8?

    How to open or convert the .avi file on the old mac running OS.10.6.8.  We tried downloading several conversion programs as well as programs that run .avi, but everyone's message could not be opened on the mac or require a fee.  Anyone able to fix it.  We have great audio video file we need to convert.

    Try to use MPEG Streamclip; You can be told to install Perian or another component, or who does not open the AVI file. AVI is a container, not a format; no single component or codec will open all reviews, and some cannot be played or converted in Mac OS X.

    (142484)

  • Convert an image to grayscale in C

    Hello. I want to convert an image, acquired by webcam, grayscale in C, using myRIO. I have a webcam connected to myRIO, working on simple image acquisition, but I can't find a way to convert the image to grayscale. I get no error to the building or a run Configuration.

    It's the image is written in the file: (black)

    The code is here:



    #include "MyRio.h".

    #define CAM_NAME 'cam1 '.
    #define CAPTURED_IMAGE_PATH ".» "/ capturedImage4.png".

    #define WINDOW_NUMBER 15 / / number of Image display window
    #define IMAQDX_ERROR_MESSAGE_LENGTH 256

    bool Log_Vision_Error (int valeurerreur);
    bool Log_Imaqdx_Error (IMAQdxError valeurerreur);

    int main (int argc, char * argv)
    {
    #if 1
    Status of NiFpga_Status;

    printf ("\n + ImageAcquisitionAndDisplayExample \n");

    Image * captureImage = NULL;
    Image * processedImage;

    Session IMAQdxSession = 0;
    /*
    * Open the myRIO NiFpga Session.
    * This function MUST be called before all other functions. After this call
    * is complete the myRIO target will be ready to be used.
    */
    status = MyRio_Open();
    If (MyRio_IsNotSuccess (status))
    {
    return the situation;
    }

    Create the Image buffer
    captureImage = imaqCreateImage (IMAQ_IMAGE_HSL, 0);
    processedImage = imaqCreateImage (IMAQ_IMAGE_HSL, 0);
    imaqSetImageSize (processedImage, 640, 480);

    Log on to the selected camera
    If (Log_Imaqdx_Error (IMAQdxOpenCamera (CAM_NAME, IMAQdxCameraControlModeController, & session)))
    Goto cleanup;

    Acquire an image
    If (Log_Imaqdx_Error (IMAQdxSnap (session, captureImage)))
    Goto cleanup;

    Process the image Captured here.
    Grayscale

    If (Log_Imaqdx_Error (imaqExtractColorPlanes (captureImage, 1, NULL, NULL, processedImage)))
    Goto cleanup;

    Write the image captured in the file
    Log_Vision_Error (imaqWriteVisionFile (processedImage, CAPTURED_IMAGE_PATH, NULL));

    cleaning:
    Log out of camera
    IMAQdxCloseCamera (session);

    Have the image
    imaqDispose (captureImage);
    imaqDispose (processedImage);

    printf ("\n--ImageAcquisitionAndDisplayExample \n");
    return 0;

    status = MyRio_Close();
    #endif
    }

    bool Log_Imaqdx_Error (IMAQdxError valeurerreur)
    {
    If {(valeurerreur)
    errorText tank [IMAQDX_ERROR_MESSAGE_LENGTH];
    IMAQdxGetErrorString (valeurerreur, errorText, IMAQDX_ERROR_MESSAGE_LENGTH);
    printf ("%s \n", errorText);
    Returns true;
    }
    Returns false;
    }

    Print the VISION Error Message
    bool Log_Vision_Error (int valeurerreur)
    {
    If ((valeurerreur! = TRUE) & (imaqGetLastError()! = ERR_SUCCESS)) {}
    char * tempErrorText = imaqGetErrorText (imaqGetLastError ());
    printf ("%s \n", tempErrorText);
    imaqDispose (tempErrorText);
    Returns true;
    }
    Returns false;
    }

    BoKnows wrote:

    Does not include the LabVIEW code you posted anything to send the image to a file.  I'm curious to know if we run out of questions at this point.  If we comment out code to convert grayscale, writing original image to the file properly or you didn't post in events where you say it works?

    I guess that LabVIEW code, you have published work to complete the task.  It's a little different from what I posted.  But I am not too concerned about that as long as things are working.

    The code works now. The problem is there:

    If (Log_Imaqdx_Error(imaqExtractColorPlanes (captureImage, 1, NULL, NULL, processedImage)))

    Instead of Log_Imaqdx_Error, it must be Log_Vision_Error.

Maybe you are looking for

  • Latest MBPs are not autonomous RAM/SSD upgrade?

    Hello I recently heard that these latest Mbit/s do not allow users to upgrade RAM or SSD. What is the latest model of MBP which will allow upgrades? Would that be a model already abandoned? Thank you very much!

  • Why can I not see some content on a website

    HelloI don't see the speed test with Firefox but with IE https://www.telecom.co.nz/internet/existingcustomers/overview/testyourspeed/?nid=mm335It comes to my ISP.I have been through all the patches of Java you suggested here, reinstalled java, does n

  • M - Audio Keystation 49th, not its entry into Logic Pro 10.2.1

    Don't know what I do wrong here. I've lived all my Logic Pro X settings and I don't understand why there is no sound coming out of my M - Audio Keystation 49th in Logic Pro 10.2.1. Can someone tell me what setting could be the cause of the issue?

  • HP 10 g2: help with sd card reader

    I just got this new tablet. And I'm just using, Samsung galaxy tab 3 at hp 10 g2. But I have a problem with the sd card. I want to insert a 32 GB. And I don't really know how to open the sd card reader, so I can insert the sd card.

  • Droid Razr XT912 NO NOTIFICATION ON MY PHONE