<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to write python downloaded images directly to JMP tables without saving them? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845089#M101965</link>
    <description>&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;Well, AI is still pretty smart.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks Experts!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-03-01_08-05-27.png" style="width: 695px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/73485i4D6837861B1A5F3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-03-01_08-05-27.png" alt="2025-03-01_08-05-27.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 01 Mar 2025 00:10:34 GMT</pubDate>
    <dc:creator>lala</dc:creator>
    <dc:date>2025-03-01T00:10:34Z</dc:date>
    <item>
      <title>How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/844993#M101951</link>
      <description>&lt;P&gt;I asked the AI to write a python asyncio to download images asynchronously.&lt;BR /&gt;Try is able to download the image, do not know how to write the image binary file directly to the JMP table without saving.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks Experts!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 14:48:14 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/844993#M101951</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-02-28T14:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845004#M101952</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-02-28_22-49-14.png" style="width: 996px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/73474iF9ACDB083BC32B9C/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-02-28_22-49-14.png" alt="2025-02-28_22-49-14.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 19:13:05 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845004#M101952</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-03-04T19:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845012#M101956</link>
      <description>&lt;P&gt;If I remember correctly one method can be found from here &lt;LI-MESSAGE title="Scripters Club Recording: Running Python Code within JSL" uid="767254" url="https://community.jmp.com/t5/JMP-Scripters-Club-Discussions/Scripters-Club-Recording-Running-Python-Code-within-JSL/m-p/767254#U767254" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 15:12:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845012#M101956</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-02-28T15:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845046#M101960</link>
      <description>&lt;P&gt;In JMP 18, only JSL can script putting images into the table.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2025 20:10:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845046#M101960</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2025-02-28T20:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845089#M101965</link>
      <description>&lt;UL&gt;&lt;LI&gt;&lt;P class=""&gt;Well, AI is still pretty smart.&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks Experts!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2025-03-01_08-05-27.png" style="width: 695px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/73485i4D6837861B1A5F3C/image-size/large?v=v2&amp;amp;px=999" role="button" title="2025-03-01_08-05-27.png" alt="2025-03-01_08-05-27.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Mar 2025 00:10:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845089#M101965</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-03-01T00:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845090#M101966</link>
      <description>&lt;UL&gt;
&lt;LI&gt;
&lt;P class=""&gt;I don't understand how it works&lt;/P&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&lt;SPAN&gt;I had previously warned the AI to call JSL in this way&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;                jmp.run_jsl = '''
                dt = Data Table("ImageTable");
                dt[{i + 1}, "Image"] = New Image(Open("{data_url}"));
                '''&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Mar 2025 19:13:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845090#M101966</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-03-04T19:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845092#M101967</link>
      <description>&lt;P&gt;Anyone trying to puzzle it out: the white text is python. the red text is jsl. the python format replaces the {} in the red jsl string (delimited by triple quotation marks) with the two parameters. the base64data is the binary data of a png or jpg file, encoded as base64, which is what newimage needs.&lt;/P&gt;
&lt;P&gt;The only part I'm surprised by is blending the two languages, although lala suggested almost the correct solution in the next post.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Mar 2025 03:43:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845092#M101967</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2025-03-01T03:43:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845094#M101969</link>
      <description>&lt;P&gt;I asked the AI and got the analysis:(grok3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a detailed English explanation of the code segment, which handles writing downloaded image data into a JMP data table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;# Write results to JMP data table
for i, (url, image_data) in enumerate(results):
    if image_data:
        dt["URL"][i] = url
        # Encode binary data to base64 and create a Blob object
        base64_data = base64.b64encode(image_data).decode('utf-8')
        # Create an image object using JSL's CharToBlob
        jsl_code = '''
        dt = Data Table("ImageTable");
        dt[{} , "Image"] = New Image(CharToBlob("{}", "base64"));
        '''.format(i + 1, base64_data)
        jmp.run_jsl(jsl_code)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;print("All images have been written to JMP table!")&lt;BR /&gt;Line-by-Line Explanation&lt;BR /&gt;for i, (url, image_data) in enumerate(results):&lt;BR /&gt;results is a list of tuples returned by asyncio.gather(*tasks), where each tuple contains (url, image_data).&lt;BR /&gt;url is the source URL of the image (a string).&lt;BR /&gt;image_data is the binary data of the image (bytes), or None if the download failed.&lt;BR /&gt;enumerate(results) provides an index i (starting at 0) for each tuple, which will be used to specify the row in the JMP data table.&lt;BR /&gt;This line iterates over all download results to prepare writing valid data into the table.&lt;BR /&gt;if image_data:&lt;BR /&gt;Checks if image_data is not None, ensuring only successfully downloaded images are processed.&lt;BR /&gt;If the download failed (image_data is None), the loop skips to the next iteration, avoiding errors in subsequent steps.&lt;BR /&gt;dt["URL"][i] = url&lt;BR /&gt;dt is the JMP data table object created earlier with jmp.DataTable("ImageTable").&lt;BR /&gt;dt["URL"] accesses the "URL" column in the data table, which has the data type jmp.DataType.Character (character type).&lt;BR /&gt;dt["URL"][i] assigns the url (the image’s source address) to the i-th row (0-based indexing) of the "URL" column.&lt;BR /&gt;This step directly uses the JMP Python API to set the cell value, recording the image’s origin.&lt;BR /&gt;base64_data = base64.b64encode(image_data).decode('utf-8')&lt;BR /&gt;base64.b64encode(image_data):&lt;BR /&gt;Encodes the binary image data (image_data, a bytes object) into base64 format, returning a bytes string.&lt;BR /&gt;Base64 is a method to convert binary data into an ASCII string, suitable for text-based environments.&lt;BR /&gt;.decode('utf-8'):&lt;BR /&gt;Decodes the base64 bytes string into a UTF-8 encoded string, producing a plain text base64 representation (e.g., "iVBORw0KGgo...").&lt;BR /&gt;This step converts the binary image data into a string format that JSL can process.&lt;BR /&gt;jsl_code = '''...'''&lt;BR /&gt;Defines a JSL (JMP Scripting Language) script as a string, which will create an image object and assign it to the data table.&lt;BR /&gt;Script content:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Data Table("ImageTable");
dt[{} , "Image"] = New Image(CharToBlob("{}", "base64"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;dt = Data Table("ImageTable");:&lt;BR /&gt;Retrieves the "ImageTable" data table in JSL, ensuring the correct table is targeted.&lt;BR /&gt;dt[{} , "Image"]:&lt;BR /&gt;{} is a placeholder that will be replaced by i + 1, representing the row number (JSL uses 1-based indexing, so i + 1 is used).&lt;BR /&gt;"Image" specifies the target column name.&lt;BR /&gt;New Image(CharToBlob("{}", "base64")):&lt;BR /&gt;CharToBlob("{}", "base64"):&lt;BR /&gt;Converts the base64-encoded string (replaced by base64_data in the second {}) into binary data (a Blob).&lt;BR /&gt;"base64" indicates to JSL that the input string is in base64 format.&lt;BR /&gt;New Image(...):&lt;BR /&gt;Creates an image object from the binary data, compatible with JMP’s "Expression" column type.&lt;BR /&gt;.format(i + 1, base64_data):&lt;BR /&gt;Uses Python’s string formatting to insert i + 1 (row number) and base64_data (base64 string) into the JSL script.&lt;BR /&gt;Example: If i = 0 and base64_data = "iVBORw0KGgo...", the resulting jsl_code becomes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = Data Table("ImageTable");
dt[1 , "Image"] = New Image(CharToBlob("iVBORw0KGgo...", "base64"));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;jmp.run_jsl(jsl_code)&lt;BR /&gt;jmp.run_jsl is a JMP Python API function that executes the JSL script.&lt;BR /&gt;Passes the generated jsl_code to JMP, performing the following:&lt;BR /&gt;Inserts an image object into the "Image" column at row i + 1 of the "ImageTable" data table.&lt;BR /&gt;The image object is derived from the base64_data and will be displayed as a viewable image in JMP.&lt;BR /&gt;print("所有图片已写入 JMP 表格！")&lt;BR /&gt;After the loop completes, prints a message in Chinese: "All images have been written to JMP table!"&lt;BR /&gt;This serves as a simple status notification to confirm the operation’s completion.&lt;BR /&gt;How It Works&lt;BR /&gt;Data Flow:&lt;BR /&gt;Retrieves url and image_data for each image from results.&lt;BR /&gt;Writes url directly to the "URL" column.&lt;BR /&gt;Encodes image_data into a base64 string.&lt;BR /&gt;Uses JSL to convert the base64 string into an image object and writes it to the "Image" column.&lt;BR /&gt;Key Technologies:&lt;BR /&gt;asyncio: Handles asynchronous image downloads.&lt;BR /&gt;base64: Encodes binary data into a string.&lt;BR /&gt;JSL: Uses CharToBlob and New Image to process images in JMP.&lt;BR /&gt;JMP Python API: Bridges Python and JSL via jmp.run_jsl.&lt;BR /&gt;Notes:&lt;BR /&gt;The "Image" column must be of type jmp.DataType.Expression to store image objects.&lt;BR /&gt;JSL uses 1-based row indexing, while Python’s enumerate is 0-based, hence i + 1.&lt;BR /&gt;Skips processing if image_data is None to avoid errors.&lt;BR /&gt;Potential Improvements&lt;BR /&gt;Error Handling: Add a try-except block around jmp.run_jsl(jsl_code) to catch JSL execution errors.&lt;BR /&gt;Performance: For large numbers of images, batch JSL execution instead of row-by-row calls.&lt;BR /&gt;Debugging: Log base64_data or jsl_code for troubleshooting.&lt;BR /&gt;This code successfully writes image data from memory into a JMP data table without saving to disk.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Mar 2025 04:35:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845094#M101969</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-03-01T04:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write python downloaded images directly to JMP tables without saving them?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845095#M101970</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have repeatedly tried python's asyncio asynchronous download speed much faster than JSL's New Multi HTTP Request().&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Mar 2025 04:44:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-write-python-downloaded-images-directly-to-JMP-tables/m-p/845095#M101970</guid>
      <dc:creator>lala</dc:creator>
      <dc:date>2025-03-01T04:44:20Z</dc:date>
    </item>
  </channel>
</rss>

