<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[Core2] How to download JPG from web and display it on screen?]]></title><description><![CDATA[<p dir="auto">I would like to download a <a href="https://mosaic.scdn.co/300/e337f3661f68bc4d96a554de0ad7988d65edb25a134cd5ccaef9d411eba33df9542db9ba731aaf98ec04f9acee17a7576f939eb5aa317d20c6322494c4b4399d9b7c6f61b6a6ee70c616bc1a985c7ab8" target="_blank" rel="noopener noreferrer nofollow ugc">JPG file from Spotify</a>, save it to micro SD card and display it on the Core2 screen. Sounds easy, but so far it didn't work for me.</p>
<p dir="auto">With <strong>MicroPython</strong> I found some challenges. I can download the image with <code>urequests</code>, and save it to micro SD card. <code>lcd.image</code> can only read files, <a href="https://forum.m5stack.com/topic/2872/bug-core2-loads-jpg-from-flash-but-crashes-with-image-from-micro-sd-card/7" target="_blank" rel="noopener noreferrer nofollow ugc">but crashes when reading from micro SD card</a>. <code>M5Img</code> only uses PNG on Core2. There seems to be a <code>lcd.image_buff</code> to maybe work around with, but I don't find any documentation.</p>
<p dir="auto">It sounds really easy, but with MicroPython I did not get far:</p>
<ol>
<li>Get JPG image from web via https [<strong>ok</strong>]</li>
</ol>
<pre><code># connect to WiFi first
import urequests
response = urequests.get('https://mosaic.scdn.co/300/e337f3661f68bc4d96a554de0ad7988d65edb25a134cd5ccaef9d411eba33df9542db9ba731aaf98ec04f9acee17a7576f939eb5aa317d20c6322494c4b4399d9b7c6f61b6a6ee70c616bc1a985c7ab8')
</code></pre>
<ol start="2">
<li>Save image to micro SD card [<strong>ok</strong>]</li>
</ol>
<pre><code>with open('/sd/images/test.jpg', 'a') as fs:
  fs.write(response.content)
import os
os.stat('/sd/images/test.jpg')
</code></pre>
<ol start="3">
<li>Display JPG image on screen from micro SD card. It usually crashes or does nothing.</li>
</ol>
<pre><code>from m5stack import *
lcd.clear(0xFFFFFF)
lcd.image(lcd.CENTER, lcd.CENTER, "/sd/images/test.jpg")
</code></pre>
<p dir="auto">Is it possible to to display a JPG from SD on the Core2 screen with MicroPython?</p>
<p dir="auto">Or should I <strong>switch to Arduino?</strong></p>
]]></description><link>https://community.m5stack.com/topic/2886/core2-how-to-download-jpg-from-web-and-display-it-on-screen</link><generator>RSS for Node</generator><lastBuildDate>Thu, 30 Apr 2026 15:16:34 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/2886.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 03 Feb 2021 14:04:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Fri, 05 Feb 2021 14:32:16 GMT]]></title><description><![CDATA[<p dir="auto">Here we go, easy work-around the faulty lcd.image():</p>
<pre><code>from m5stack import *
buffer = open("/sd/images/test.jpg").read()
lcd.image_buff(lcd.CENTER, lcd.CENTER, buffer)
</code></pre>
]]></description><link>https://community.m5stack.com/post/12319</link><guid isPermaLink="true">https://community.m5stack.com/post/12319</guid><dc:creator><![CDATA[mb]]></dc:creator><pubDate>Fri, 05 Feb 2021 14:32:16 GMT</pubDate></item><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Fri, 05 Feb 2021 12:31:29 GMT]]></title><description><![CDATA[<p dir="auto">The <code>lcd.image()</code> doesn't work with <code>/sd</code>, so I just tested undocumented(?) <code>lcd.image_buff(x, y, buffer)</code> and it works:</p>
<pre><code>response = urequests.get('https://mosaic.scdn.co/300/e337f3661f68bc4d96a554de0ad7988d65edb25a134cd5ccaef9d411eba33df9542db9ba731aaf98ec04f9acee17a7576f939eb5aa317d20c6322494c4b4399d9b7c6f61b6a6ee70c616bc1a985c7ab8')

lcd.image_buff(lcd.CENTER, lcd.CENTER, response.content)
</code></pre>
<p dir="auto">Now I only have to read the file from <code>/sd</code>into a buffer and hopefully get around the crash.</p>
]]></description><link>https://community.m5stack.com/post/12306</link><guid isPermaLink="true">https://community.m5stack.com/post/12306</guid><dc:creator><![CDATA[mb]]></dc:creator><pubDate>Fri, 05 Feb 2021 12:31:29 GMT</pubDate></item><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Wed, 03 Feb 2021 19:38:41 GMT]]></title><description><![CDATA[<p dir="auto">I tried with various sizes, it seems to not make a difference. The same image is displayed fine when loaded from <code>/flash</code>, but it crashes when loaded from <code>/sd</code>.</p>
]]></description><link>https://community.m5stack.com/post/12280</link><guid isPermaLink="true">https://community.m5stack.com/post/12280</guid><dc:creator><![CDATA[mb]]></dc:creator><pubDate>Wed, 03 Feb 2021 19:38:41 GMT</pubDate></item><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Wed, 03 Feb 2021 16:37:27 GMT]]></title><description><![CDATA[<p dir="auto">Is it possible that lcd.image expects an image smaller than the lcd?  Perhaps it needs to be resized.<br />
Have you tried displaying a small image?</p>
]]></description><link>https://community.m5stack.com/post/12276</link><guid isPermaLink="true">https://community.m5stack.com/post/12276</guid><dc:creator><![CDATA[JackH]]></dc:creator><pubDate>Wed, 03 Feb 2021 16:37:27 GMT</pubDate></item><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Wed, 03 Feb 2021 14:12:02 GMT]]></title><description><![CDATA[<p dir="auto">When replacing SD with flash it just works seamlessly, this drives me crazy !</p>
<pre><code># connect to WiFi first

import urequests
response = urequests.get('https://mosaic.scdn.co/300/e337f3661f68bc4d96a554de0ad7988d65edb25a134cd5ccaef9d411eba33df9542db9ba731aaf98ec04f9acee17a7576f939eb5aa317d20c6322494c4b4399d9b7c6f61b6a6ee70c616bc1a985c7ab8')

with open('/flash/images/test.jpg', 'a') as fs:
  fs.write(response.content)
import os
os.stat('/flash/images/test.jpg')

from m5stack import *
lcd.clear(0xFFFFFF)
lcd.image(lcd.CENTER, lcd.CENTER, "/flash/images/test.jpg", 0)
</code></pre>
]]></description><link>https://community.m5stack.com/post/12275</link><guid isPermaLink="true">https://community.m5stack.com/post/12275</guid><dc:creator><![CDATA[mb]]></dc:creator><pubDate>Wed, 03 Feb 2021 14:12:02 GMT</pubDate></item><item><title><![CDATA[Reply to [Core2] How to download JPG from web and display it on screen? on Wed, 03 Feb 2021 14:08:23 GMT]]></title><description><![CDATA[<p dir="auto">I tried various ways with <code>lcd.image</code>, but it usually crashes or just does not do anything when called first.</p>
<pre><code>lcd.image(0, 0, "/sd/images/test.jpg")
lcd.image(0, 0, "/sd/images/test.jpg", 0)
lcd.image(lcd.CENTER, lcd.CENTER, "/sd/images/test.jpg")
lcd.image(lcd.CENTER, lcd.CENTER, "/sd/images/test.jpg", 0)
</code></pre>
]]></description><link>https://community.m5stack.com/post/12274</link><guid isPermaLink="true">https://community.m5stack.com/post/12274</guid><dc:creator><![CDATA[mb]]></dc:creator><pubDate>Wed, 03 Feb 2021 14:08:23 GMT</pubDate></item></channel></rss>