Support

Account

Home Forums Add-ons Gallery Field WordPress ACF Rest API, get images in base64 format

Unread

WordPress ACF Rest API, get images in base64 format

  • I’m using wordpress only for the API with custom endpoints created with ACF. I was wondering if there’s any way to return images URL + base64. I need also this format to create a PDF in my website.

    Here’s the response from wordpress API:

    
    {
     id: 179,
      acf: {
       gallery: [
        {
         ID: 700,
         id: 700,
         title: "Title",
         filename: "filename.jpg",
         filesize: 388629,
         url: "https://exemple.com/wp-content/uploads/image.jpg",
         link: "https://exemple.com/wp-content/uploads/",
         alt: "",
         author: "2",
         description: "Description",
         caption: "Caption",
         name: "name",
         status: "inherit",
         uploaded_to: 0,
         date: "2019-04-03 14:05:27",
         modified: "2019-04-03 14:06:11",
         menu_order: 0,
         mime_type: "image/jpeg",
         type: "image",
         subtype: "jpeg",
         icon: "https://exemple.com/wp-content/uploads/image.jpg",
         width: 1200,
         height: 1600,
          sizes: {
            thumbnail: "https://exemple.com/wp-content/uploads/image.jpg",
            thumbnail-width: 150,
            thumbnail-height: 150,
            medium: "https://exemple.com/wp-content/uploads/image.jpg",
            medium-width: 225,
            medium-height: 300,
            medium_large: "https://exemple.com/wp-content/uploads/image.jpg",
            medium_large-width: 640,
            medium_large-height: 853,
            large: "https://exemple.com/wp-content/uploads/image.jpg",
            large-width: 640,
            large-height: 853
          }
        },
        ...
    
    

    Is there any way that base64 image format can appear also in json ?

    I’m using [jsPDF][1] to create pdf:

    
          const doc = new jsPDF("l", "mm", "a4");
           api.map(item => (
            doc.addPage("l", "mm", "a4")
            doc.text(35, 25, item.title)
            doc.addImage(item.BASE64, 'JPEG', 15, 40, 180, 160)
          ))
          doc.save("my-pdf");
    

    Thanks

    [1]: https://parall.ax/products/jspdf

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.