About This Article
This article is created using an automated generation workflow leveraging generative AI. Operations, observations, and limitations are organized by referencing official documentation and fixed course code.Verification Status: Partial matching with official information and implementation. Real browser behavior for the fixed version has not been verified.
When attaching a notification card to social media or chat, it is convenient to extract it as an image. Convert only the card portion of the screen into a PNG.
- Key Terms to Know First
- Thinking in Terms of a Processing Flowchart
- Operating the Live Demo
- Key Points of the Code
- When using in production
- Convert to PNG by changing only the announcement text
- Limit the DOM to be converted to an image
- Pay attention to fonts and external assets
- Isolate failures and verify before sharing
- Verification Scope
- References
- GitHub sample
Key Terms to Know First
DOMis a mechanism for manipulating page elements.
PNGis an image storage format.
Thinking in Terms of a Processing Flowchart
Read from left to right. Anticipate how changing the card to be displayed affects the PNG output.
flowchart LR
A["告知文"] --> B["見せたいカード"] --> C["PNG出力"]
Operating the Live Demo
Change the notification text. Check whether the control panel is captured in the output image.
How to Interpret the Results
Only the card becomes an image.
Expanding the output target to the entire parent screen includes the control buttons as well. Keep the range you want to output as an independent element.
Key Points of the Code
Limit the target of toPng to the card only and display the result as an image.
The implementation can be checked in the implementation code on the demo screen.
When using in production
Mixing asset sources may cause image generation to fail. Align the image retrieval conditions first.
Convert to PNG by changing only the announcement text
Start by executing with a heading titled Regular Maintenance Notice. The demo creates a card, places the entered heading inside it, and includes the fixed body text Some functions will be suspended during maintenance. Verify that the converted image and a link to save as PNG are displayed. Next, change the heading to Notice of Reception Hours Change and perform the same operation. Observe whether the heading in the image changes while the fixed body text remains the same. Open notice.png saved from the link and check whether operation buttons or input fields are captured.
Text after being converted to an image cannot necessarily be selected and copied like the original HTML. A PNG is a raster image and does not retain the original document structure. When sharing announcements, providing the text content alongside the image makes the information easier for screen reader and search users to access.
Limit the DOM to be converted to an image
The tutorial specifies a card width of min(340px, 100%) and places the entered heading and fixed body text inside it. Only the card element is passed to toPng. Instead of capturing the entire operation screen, specified DOM elements are converted to images. Changing the target of conversion also changes the included elements, so it is important to separate the portion to be distributed from the portion required for operations. Since the card width is also affected by the parent layout area, do not assume fixed pixel dimensions for the final image.
html-to-image duplicates the DOM content, handles styles, and converts it to an image via SVG or Canvas. In the tutorial, the return value of toPng is passed to the image src, and the same value is assigned to the href of the save link. The design allows comparing the original card display with the generated image. Unlike a full-page screenshot, the target is the content of the specified element.
Pay attention to fonts and external assets
The tutorial specifies skipFonts:true. This setting skips the process of fetching and rendering fonts, and does not guarantee that the appearance will be identical to the original page fonts. When using custom fonts or external images in actual announcement cards, verify asset accessibility, font licensing terms, and the resulting converted image. In environments where external resource retrieval is restricted, conversion to an image may fail even if the content renders on screen.
Insert a long announcement text and observe text wrapping and box height. Check separately whether headings and body text fit without truncation on narrow screens and whether the image remains readable when scaled down. Also verify whether the image save format, output size, and background color meet your requirements. Testing by adding elements from the original card one by one, beyond just text length, is useful.
Isolate failures and verify before sharing
If the original card is generated but no image appears, the image conversion stage may have failed. Check for missing dependencies or asset loading errors in the Console and Network tabs, and reproduce the issue by reverting to a minimal card that contains no external images or custom fonts. If the image is created but cannot be saved, check the download settings. Open the file to visually inspect it, distinguishing between successful rendering and successful saving.
When converting internal announcements into images, verify that displayed names, dates, and contact information are correct. Visually inspect the generated output rather than relying solely on element selection to ensure no restricted information is included for distribution. The public demo uses placeholder text. This tutorial does not include functionality for posting to external social media services, covering only the generation and local saving of the PNG by the user.
Verification Scope
The specified tutorial version is html-to-image 1.11.13. Verify the target card, skipFonts:true, and the save link notice.png using fixed HTML. DOM conversion and PNG generation are not executed here. CDN retrieval, fixed version matching of licenses, and actual rendering must be checked separately.
References
Official API and Documentation(Accessed: November 30, 2026)
