Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7758317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:19:40+00:00 2026-06-01T13:19:40+00:00

I am trying to create & save images from data in an email from

  • 0

I am trying to create & save images from data in an email from the base64 data of an actual image that was in the html body that appears inline such as:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAE==">

But i’m trying to create them sequentially, as there could be more than one image tag in the html body, where the variable $html_part is the html body of the email.
I just need some assistance in coming to a solution on what i’m doing wrong.

    $img_tags = preg_match('/<img\s+(.*)>/', $html_part, $num_img_tags);
    $num_img_tags = count($num_img_tags);

    echo $html_part;
    for ($i = 1; $i <= $num_img_tags; $i++) {       
    preg_match('/<img\s+(.*)\s+src="data:image\/(.*);(.*),(.*)"\s+(.*)>/i', $html_part, $srcMatch);
{   
    foreach($srcMatch[4] as $im_data)
    {
        $ufname = "image0".$num_img_tags.".jpg";
        echo "<h1>$ufname</h1>";
            $im_data = base64_decode($im_data);
            $im = imagecreatefromstring($im_data);
            if ($im !== false) {
            header('Content-Type: image/jpeg');
            imagejpeg($im, $ufname);
            imagedestroy($im);
            }
            else {
            echo 'An error occurred.';
            }
    }

}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:19:42+00:00Added an answer on June 1, 2026 at 1:19 pm

    Your code is impossible – you cannot do a header() call after you’ve performed ANY output. You can also not output multiple images in the same ‘document’. You also cannot output html (the <h1> stuff), images (header('Content-type:...'), etc… all within the same document.

    As well, parsing/processing HTML with regexes is dangerous. A single malformation of the source document and your regexes will happily feast on garbage and produce garbage for you. Do not use regexes on html… every time you do, Alan Turing kills a kitten. Use a DOM parser instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create two functions: get & set, that both accept an arbitrary
I'm trying to create some Menu Item with Image & Label, using barry's class
I'm simply trying to create a secure user file that will save basic login
I'm trying to copy some binary data from my IStream instance (since Gdiplus::Image only
I'm trying to create a save & load module in my app. So the
I am trying to learn & create Visual Studio templates and as per this
I'm trying to learn Regex & URL Rewriting in PHP. How can I create
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I'm trying to create a node (B type) & assign it to a A
I am trying to create a Macro that either runs on close or on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.