#How to import images from remote content (Headless)
16 messages · Page 1 of 1 (latest)
Using the image component you can achieve this
Can you give me an example ?
If get a remote content (page content from WP with images) how can I import the images included in this content ?
Do you have access to an image url?
Using the <@&1026769514878205992>/image integration with that url should include it locally and optimize the image
no I only get content from wordpress via graphql
don't know what is inside
I need to check if image in this content and have them then imported
Hey @hybrid bluff you can find out more infor about what our good friend @pulsar locust was saying with the astro image integration
https://docs.astro.build/en/guides/integrations-guide/image/#remote-images
If you have the url of the end point then you just pass that in as the <Image src={urlForWPImg} aspectRation="16:9"/>
No I mean how to extract from a content coming from a WP page
I get the content without knowing what is inside
if any image in how to convert and import it ?
Are you trying to literally import the actual webpage HTML into Astro as opposed to using the Wordpress headless API. You should be fetching your data with the API which will return JSON to your Astro project. In the JSON should see URL(s) to your Wordpress image(s). It's that URL that you feed to the Astro Image plugin and it will download it for you, optimize it and store it locally.
@hybrid bluff are you talking about inline images within the WP's content block, either within the classic tinymce editor or gutenberg editor? If so, I imagine this content needs to be structured with JS first. Unfortunately, this will take extra work to do.
Otherwise, If you're referring to WP's featured image, that's pretty simple since it's a standalone object and already structured. Therefore, easy to use with Astro's image component. Your component will end up looking something like this within your astro component or file based on posts:
<Image src={post.featuredImage?.node.mediaItemUrl} alt={post.altText ? node?.altText : post.title} width={post.featuredImage.node.mediaDetails.width} height={post.featuredImage.node.mediaDetails.height} />
Make sure you query for these fields on the posts type:
posts {
featuredImage {
node {
mediaItemUrl
altText
mediaDetails {
sizes {
height
width
sourceUrl
}
}
}
}
}