I need help displaying an image string as an image. I'm calling an API with curl, after that I get the image string which I can output like this:

<img src="data:image/jpg;base64,<?php echo $_SESSION['miar']['Image']; ?>" />

however, it spits out a whole string beginning with data:image/jpg;base64/aksdjfksjkdfjlksdlfjakjsdfljasjdfjsjljfasldjf
what I would like to do is setup either a tmp filename that I can use like this <img src="thename.jpg" />
is there a way to do this?

Thanks in advance! 🙁 😕

    Decode it programmatically, and write it to an image file, then set the src to the path+name of the image file you wrote.

      Thanks Derokorian for your fast response. I get a series of characters when I base64_decode, do I need to do anything else?

      &#65533;&#65533;&#65533;&#65533;&#65533;JFIF&#65533;&#65533;`&#65533;`&#65533;&#65533;&#65533;&#65533;&#65533;C&#65533;		
      
       $.' ",#(7),01444'9=82<.342&#65533;&#65533;&#65533;C			
      
      2!!22222222222222222222222222222222222222222222222222&#65533;&#65533;&#65533;&#65533;Z&#65533;Z"&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;	
      &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;}&#65533;!1AQa"q2&#65533;&#65533;&#65533;#B&#65533;&#65533;R&#65533;&#65533;$3br&#65533;	
      %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;	
      &#65533;&#65533;&#65533;&#65533;&#65533;&#65533;w&#65533;!1AQaq"2&#65533;B&#65533;&#65533;&#65533;&#65533;	#3R&#65533;br&#65533;
      $4&#65533;%&#65533;&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;?&#65533;&#65533;&#65533;&#65533;&#65533;&F&#65533;}i&#65533;&#65533;&#65533;&#65533;&#65533;4&#65533;_v&#65533;\&#65533;q.&#65533;&#1617;A&#65533;&#65533;Oz&#65533;&#65533;&#65533;&#65533;&#65533;w&#65533;z&#1142;&#65533;&?&#65533;&#65533;&#65533;&#65533;&#65533;<d[&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;ZHlY&#1589;&#65533;&#10036;&#65533;&#65533;&#65533;&#65533;&#65533;}&#65533;&#65533;&#1269;+&#65533;Z{&#65533;&#65533;&#65533;&#65533;gnMKo&#65533;&#65533;)&#65533;6m&#65533;&#65533;&#65533;&#65533;Z&#65533;8l&#65533;AR=&#65533;S&#65533;V&#65533;6^
      !^[&#65533;&#65533;J&#65533;&#65533;&#65533;?5&#65533;_&#65533;|&#65533;?:&#65533;,&#65533;I&#65533;&#65533;&#65533;&#65533;&#65533;&#1611;J&#65533;8&#65533;'<&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;[&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;,]&#65533;&#590;T&#65533;&#65533;s&#65533;8;&#65533;{&#65533;&#930;&#65533;>&#65533;&#65533;Ob&#65533;&#65533;&#65533;&#65533;6&#65533;D&#65533;'&#65533;&#504;=&#65533;GJ&#311;k&#65533;)D&#65533;r<	&#65533;&#65533;X&#65533;=&#65533;&#65533;&#65533;&#65533;V&#65533;&#65533;S&#8785;&#65533;&#65533;T&#65533;.&#65533;&#65533;&#65533;^&#65533;&#65533;;Q%&#65533;&#65533;N	&#65533;&#65533;/Koi=&#65533;&#756;FI"K&#65533;H&#1731;&#65533;&#65533;&#65533;5(&#65533;t&#65533;&#1410;&#65533;&#65533;&#65533;&#65533;P"&#65533;J&#65533;^&#65533;&#65533;&#65533;mrfY&#65533;'&#65533;[<&#65533;&#65533;k&#1276;&#65533;[+&#712;&#65533;&#65533;h&#65533;?&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;n&#65533;&#65533;9&#65533;u'&#65533;&#65533;&#65533;Q{2e&#65533;,&#65533;{&#65533;&#65533;&#65533;&#65533;-~s&#65533;&#65533;&#65533;&#65533;w&#65533;&#65533;&#65533;+s&#65533;&#65533;m2&#65533;&#65533;"&#65533;[&#1657;&#65533;Ol&#65533;9_&#65533;O&#65533;t&#65533;m)+&#65533;	G&#65533;r&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;K&#65533;@&#65533;&#65533;g&#65533;c)&#65533;&#65533;&#65533;D&#65533;dJFFOZr"&#65533;64&#65533;T&#65533;m&#65533;n&#65533;@#&#65533;k&#1212;&#4472;&#65533;&#65533;&#65533;,&#65533;"g&#65533;=k&#820;+&#65533;&#65533;CPy&#65533;&#65533;&#65533;R&#65533;&#65533;&#65533;n&#65533;
      &#65533;&#65533;&#65533;\u&#65533;C&#1121;^&#65533;&#65533;zlQ&#65533;&#65533;uc&#1847;5}t+M&#65533;i&#65533;L&#65533;j&#65533;EG?x&#65533;U&#65533;&#65533;&#65533;&#65533;P&#65533;:&#65533;]&#65533;gL&#65533;16&#65533;&#44355;}&#65533;&#65533;&#65533;&#65533;I&#65533;&#65533;&#65533;]&#65533;&#1317;&#65533;&#381;&#65533;h<c&#65533;&&#65533;j7&#65533;&#65533;}o&#65533;QX&#65533;h&#65533;&#65533;&#65533;&#65533;[I&#65533;&#895;>x&#65533;5&#65533;&#65533;d&#65533;#&#65533;W&#65533;k0"&#65533;&#544;q&#1966;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;i&#65533;&#65533;%&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;+&#65533;&#65533;&#65533;lde&#65533;&#65533;&#65533;&#65533;G&#65533;&#65533;&#65533;l&#65533;&#65533;	&#65533; g&#65533;&#1778;{&#65533;X&#493;Z&#65533;Y&#65533;h&#65533;Xa&#65533;&#65533;&#65533;&#65533;Q&#65533;&#65533;&#65533;&#65533;&#65533;K&#65533;W&#65533;&#65533;b&#65533;&#65533;_&#65533;c&#65533;&#65533;&#65533;&#65533;e&#65533;,y&#65533;5&#65533;&#65533;x?P&#1340;;&#65533;&#65533;&#65533;&#65533;aK<&#65533;8$&#65533;g&#65533;&#65533;5&#65533;&#65533;&#65533;o#&#1982;&#65533;&#65533;&#65533;H&#65533;&#65533;v&#65533;&#65533;:(&#65533;&#65533;&#65533;&#65533;ZV&#65533;&#65533;&#65533;xJ*m&#65533;t<o&#65533;&#65533;&#65533;&#65533;A.&#65533;&#65533;&#65533;&#65533;&#65533;&#58901;c&#65533;j&#65533;&#65533;j&#65533;&#441;&#65533;&#65533;&#65533;&#36525;&#65533;&#65533;&#65533;7&#65533;1&#65533;B&#65533;*&#65533;&#37869;u&#65533;ö@q&#65533;&#65533;&#18233;&#65533;&#65533;J&#65533;,LK&#65533;zkB&#65533;5}-&#65533;
      &#65533;&#65533;&#1338;_&#65533;ondT&#65533;&#65533;&#65533;&#65533;{&#65533;m7#&#65533;&#65533;&#65533;P&#65533;t&#65533;&#65533;a
      &#65533;&#65533;T&#65533;<&#65533;P?*m&#65533;&#65533;&#65533;N&#65533;
      M T&#65533;&#65533;:RrihZ&#65533;&#1959;Iy2&#65533;&#65533;&#65533;&#1720;&#65533;G&#282;Z&#65533;G&#65533;q&#65533;K&#65533;&#65533;U&#65533;]&#65533;o&#65533;K&#65533;
      &#65533;S&#999;&#1212;&#65533;&#65533;&#65533;	&#65533;u&#1278;%Bab2&#65533;&&#65533;&#65533;Z&#65533;&#65533;&#65533;&#50011;&#65533;OG&#65533;&#65533;.e&#65533;&#65533;&#65533;&#65533;/&#65533;&#65533;&#41060;&#65533;l&#65533;`2U&#65533;B+&#65533;&#65533;&#65533;Z&#65533;&#65533;&#65533;&#65533;Zt&#65533;&#65533;&#65533;&#65533;2&#65533;&#65533;V&#65533;&#65533;%X&#65533;&#65533;t,@&#65533;>&#65533;&#65533;&#65533;f.&#65533;~K&#65533;&#1238;~c9&#65533;Mæ~&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;UIa&#65533;&#65533;q&#65533;LEY&#65533;&#65533;&#65533;&#65533;A]&#65533;H&#65533;&#65533;^&#65533;&#65533;&#65533;&#65533;,|&#1534;&#65533;[&#65533;&#65533;&#65533;;m&#65533;&#65533;&#65533;ma&#65533;&#65533;&#65533;&#65533;?&#65533;|&#65533;&#65533;g&#65533;ko&#65533;V&#65533;_&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;S&#65533;&#65533;&#65533;&#65533;SVF&#65533;*&#65533;r&#1257;&#65533;23&#65533;$&#65533;&#1460;/CM&#65533;&#65533;w&#65533; 2g'&#65533;W
      &#65533;&#65533;&#65533;g
      &#65533;+&#65533;3&#65533;&#65533;&#65533;R&#65533;Q&#65533;]C&#65533;6&#65533;d&#65533;&#65533;s&#65533;V=&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;tpEg	&#19640;[x&#65533;&#65533;&#65533;C&#633;&#65533;@&#65533;&#511;&#65533;i&#65533;&#65533;&#65533;Ff62&#65533;&#65533;&#65533;O}J&#27713;&#65533;("&#65533;D(&#65533;(R7&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;V&#65533;&#65533;'&#65533;&#65533;c&#65533;;}>&#65533;"&#65533;M|&#65533;&#65533;&#65533;&#65533;k&#65533;&#65533;&#65533;,&#65533;u&#65533;&#65533;,&#65533;&#65533;d&#65533;:&#65533;&#65533;i&#65533;&#65533;&#65533;&#65533;K&#65533;3&#65533;&#65533;&#65533;&#65533;&#65533;%I&#65533;3&#65533;z&#1503;&#65533;m&#65533;&#65533;H&#65533;$"<&#65533;Ez%&#65533;&#65533;Gf#-&#65533;,`&#65533;&#65533;}k&#65533;u&#65533;BX&#65533;&#65533;&#65533;y&#65533;A&#65533;X&#65533;&#65533;&#65533;&#65533;&#65533;VQ&#65533;s7&#65533;U&#65533;&#65533;&#65533;\&#65533;g&#65533;&#65533;&#65533;x&#65533;&#65533;&#65533;&#65533;&#65533;*&#65533;n&#65533;&#65533;&#65533;s&#65533;c&#65533;kB4a&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;<&#65533;&#65533;&#65533;M&#65533;&#909;&#65533;&#65533;j&#65533;[^E{k,e&#65533;&#65533;&#65533;H&#65533;&#1886;&#65533;#&#65533;&#65533;]V&#65533;&#65533;}#A&#65533;d&#65533;Nk&#65533;$)&#65533;&#65533;&#65533;nNp0&#65533;u&#65533;:&#65533;3_&#65533;&#493;i&#65533;~&#1028;&#65533;&#65533;2&#65533;&#65533;_&#65533;&#65533;&#65533;&#65533;&#65533;iV&#65533;&#65533;&#65533;"&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;yI{&#65533;V~&#65533;&#65533;i>&#65533;&#65533;q&#65533;&#65533;&#65533;&#65533;S&#65533;nn&#65533;&#65533;&#65533;0&#65533;&#65533;&#65533;&#65533;&#1823;N&#65533;&#65533;kE&#65533;uT(&#65533;29&#65533;&#65533;YW&#65533;Gb&#65533;G&#65533;&#65533;&#65533;F&#65533;F&#65533;1&#65533;&#65533;U[&#760;$P01&#65533;Nj&#65533;Q&#65533;&#65533;&#65533;F&#65533;6&#65533;4<^>&#65533;9&#65533;g&#65533;&#65533;&#65533;&#65533;~&#65533;Y$
      %&#65533;c
      @&#65533;&#65533;[&#65533;&#65533;l&#65533;&#65533;[&#65533;s&#65533;&#65533;=&#65533;&#65533;&#65533;&#65533;e&#65533;&#441;&#65533;~&#65533;{Qf&#65533;&#65533;E&#1773;Gz\&#65533;&#1848;&#65533;&#65533;&#65533;(&#65533;^u&#65533;_B&#65533;&#65533;PDJ6&#423;&#65533;&#65533;{&#1335;&#65533;&#65533;&#937; &#65533;X&#65533;&#65533;b_&#65533;=&#65533;&#65533;Te
      1]T&#65533;&#65533;npV&#65533;&#28422;J&#65533;
      &#65533;&#65533;&#65533;^{&#1368;&#436;#&#468;&#65533;8&#1385;&#65533;}&#65533;Fk&#65533;&#65533;49&#65533;}&#65533;ms,p&#65533;{&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;AGcW()+1&#65533;N.&#65533;&#65533;&#7886;&#65533;|j'&#65533;&#65533;Hdx&#993;&#1509; !&#65533;O&#923;&#65533;@#&#65533;ti&#65533;m&#65533;&#65533;dg^.:&#65533;&#65533;VI>&#65533;&#65533;8r&#65533;&#483;N|&#1145;&#65533;>&#65533;&#65533;N&#65533;&#65533;&#65533;&#65533;l&#65533;&#65533;&#65533;&#65533;&#65533;]&#65533;&#65533;&#65533;v&#65533;&#65533;C&#65533;a&#65533;&#65533;&#65533;&#65533;sw"fM&#65533;&#65533;&#65533;aY&#65533;0&#65533;&#65533;JkIa2&#65533;:&#65533;P>&#65533;<=&#65533;Q&#65533;]DH&#65533;c&#65533;~U&#65533;x
      &#65533;")7&#65533;1-&#65533;d&#65533;&#430;&#65533;&#65533;&#65533;&#65533;X&#65533;6j&#65533;T&#65533;&#65533;u&#65533;&#1807;&#65533;[&#65533;P7g^&#65533;&#1992; &#65533;5M&#65533;OJ&#65533;o&#65533;&#65533;D<ch&#65533;$&#65533;K&#65533;&#65533;l1?&#65533;y&#65533;E>&#65533;&#65533;U&#65533;&#65533;#&;f&#65533;&#65533;&#65533;g&#65533;8&#65533;x&#53718;&#65533;&#65533;&#65533;u&#65533;R&#65533;&#65533;&#65533;&#65533;&#65533;W@mm&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;&#65533;1Y&#65533;&#65533;

      that is the string I get back.

        that string is when I applied the utf-8 characterset to display in a webpage. the raw string looks like this:

        /9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCABaAFoDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3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k+XsKotuuJGlc5ZjkmtCNGEajf0ArvWiPIqPmk2dzo3g3wtqF5NbXkV7ayxlgf8ASMHdnpgjg+tdVoXgfSNB1WSbTmuJJCmwtO4bbk5wMAe1dZ468DNf3cetaYh+0IQbqBODMo/iX/bH6/WnaVbQ/ZUeIhkI4P8AnvWFeUl7p1YaEX7xBsNpPu2/unH5GrqyBhntU81uHQhunpWTMJbV9qjcn06VzWsdRfV1VCjqGjI5yOtZV9JHC2LaR4CP7hpGv0YAMcAdulVby7gkUBEwMc5OapFRnZ6mRrU2oTQ8Xj7SBwM546Vn6PLb+H7WWSQKJZRjCgZA9Kj1W+n3bLXeW9AOBXP38z2lpLeXZZjGudgPfoB7UWb0FOa3RdutR3pc3Ny4jR+cE8Io6V51ql8dQvmlUERKNsan0/x71Le6lc6pIPOIWIH5Yl+6Pf3NVGUKMV1UqfJucFao5ryGGUqMCr8cx8teew7VmMa0I8eUnzgcDtWpzn24Rmuf1TQ5BO19pm0XDHMsDHCTe/8Ast79+9dBR2NXKCkrMcZOLuji4buO73xqGSeM4khkGHjPoR/XpQYRICGPT86b40Aj1XRpkG2V5GRnXgsuOhPp7VZJPrXDOHLKx6NOfNG5iz6YrE7toB7jisPUbKK2+4STXYT/AHa5jUP9Yayehe5zdyJmTYuFz2FZtjCLzUprSWEy2joYp1A+8DwQPcdR711ESLhjtH5V0XgKCH+wIn8pN7MxLbRk/MaukryM6r5YnzZqulT6HrF1ptyP3lvIUDdnXqrfiCD+NU3yT0r1b4ywRDxjaMIkDPZLuIUZbDEDP4V5+kUePuL+VdrOIyY7ZpGA4Ge5OK147YeWvMPQdetSmNP7i/lXQG1t8/8AHvF/3wKluzFZH//Z

          You just need to take that raw string and put it into a file now with the correct extension. For example if its a jpg you might do:

          file_put_contents('api_image.jpg',$rawString);
          echo '<img src="api_image.jpg" />';
          

          At least that's my best guess. 😃

            Derokorian,

            I've tried that but it didn't work. any other suggestions?
            I used both $image = base64_decode($myimage); and the raw response from the curl. Both return nothing.

              If your original approach worked:

              jvilchis;11016685 wrote:
              <img src="data:image/jpg;base64,<?php echo $_SESSION['miar']['Image']; ?>" />

              Then all you need is two simple function calls - [man]base64_decode/man and [man]file_put_contents/man.

                bradgrafelman ---
                i'm trying to create the image with the string i get back from

                <img src="data:image/jpg;base64,<?php echo $_SESSION['miar']['Image']; ?>" />

                generate an image in my server and output it to the page in <img src="name-of-image-generated.jpg" /> I've tried various actions to get create a file using file_put_contents(); with no luck, I've tried base64_decode(); and I just get an error: "image cannot be displayed because it contains errors" is there a way to check the error in the jpg creation?

                thanks in advanced.

                  Can you show us the exact code you used when you tried to decode the data and write it out to a file?

                  EDIT: Just for illustration/clarity of what I meant above... if the "data:" representation of the image data successfully displayed the image in your browser, then I don't see why this:

                  file_put_contents( 'name-of-image-generated.jpg', base64_decode( $_SESSION[ 'miar' ][ 'Image' ] ) );

                  wouldn't work (barring any filesystem-related issues, of course).

                    bradg... sure, here it is:

                    $customer = $response['Image']; // the response is a json_decode for the curl
                    $nameofimage = $response['Name'];// the name of an object via the api
                        $data = $customer; // I made the path to get the image into this variable
                        $data = base64_decode($data);
                        header('Content-Type: image/jpg');
                        file_put_contents($nameofimage.'_image.jpg' , $rose);   

                      Few things:
                      1) In that code you are not attempting to set an img tag at all.
                      2) You are putting the contents of $rose into the file, but where do you define the variable $rose?
                      3) You are outputting a header response, but for what reason?
                      4) What this means is, you putting the contents of an undefined variable into a file, and responding to the request with an http header (and nothing else at all)

                        derokorian -- you are correct. Do you think I can do the following?

                        $customer = $response['Image']; // the response is a json_decode for the curl
                        $nameofimage = "test";// the name of an object via the api
                            $data = $customer; // I made the path to get the image into this variable
                            $data = base64_decode($data);
                            file_put_contents($nameofimage.'_image.jpg' , $data);
                        echo '<img src="test_image.jpg" />';  // just for sampling purposes.
                        

                          You could, if test happened to be the value of $nameofimage, but you need the src to match the file name you're putting contents in. IE:

                          file_put_contents($nameofimage.'_image.jpg' , $data);
                          echo '<img src="'.$nameofimage.'_image.jpg" />';
                          

                            Tried it and I get nothing. I've even tried this:

                            $customer = $response['Image'];
                            file_put_contents('api_image.jpg' , $customer);
                            

                            I checked the api_image.jpg in my server and nothing gets written to it. I set the permissions to that file to 777 and even the folder that it is in.

                            wouldn't that write some stuff to that api_image.jpg?

                            thanks,
                            jv

                              ok.. finally, I have a result.

                              $data = $customer; // I made the path to get the image into this variable
                              $data = base64_decode($data);	
                              file_put_contents($nameofimage.'_image.jpg' , $data);
                              echo '<img src='.$nameofimage.'_image.jpg />';  

                              now! the question is: How do I generate the filename_image.jpg along with permissions of 777?

                              thanks,
                              jv

                                Maybe use [man]chmod/man after you create the file?

                                  ok.. that one was a bit easier:

                                  $my_file = $nameofimage.'_image.jpg';
                                  $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); 
                                  

                                    This is what I have, I think this is done, now I have to setup a folder in prod server that will host these files. Thank you all for your help! The code below works for generating images.jpg from an API that shoots images as strings in base64. Things to consider when using this:
                                    chmod for folder to 775 or 777 depending on security, and I think that is all.

                                    Thanks again to all the people that helped especially Derokorian.

                                    $my_file = $nameofimage.'_image.jpg';
                                    $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file
                                    $data = $customer; // I made the path to get the image into this variable
                                    $data = base64_decode($data);	
                                    file_put_contents($nameofimage.'_image.jpg' , $data);
                                    
                                    echo '<img src='.$nameofimage.'_image.jpg width="100px"/>';  
                                      jvilchis;11016853 wrote:

                                      Things to consider when using this:
                                      chmod for folder to 775 or 777 depending on security

                                      A potentially better solution could be to use something like suPHP, meaning you could use much safer directory permissions such as 711.

                                      jvilchis;11016853 wrote:
                                      $my_file = $nameofimage.'_image.jpg';
                                      $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file
                                      $data = $customer; // I made the path to get the image into this variable
                                      $data = base64_decode($data);	
                                      file_put_contents($nameofimage.'_image.jpg' , $data);
                                      
                                      echo '<img src='.$nameofimage.'_image.jpg width="100px"/>';  

                                      Some comments:

                                      1. Why create $my_file at all if you're going to repeat its contents in a hardcoded manner throughout the rest of the code?

                                      2. There's no need for the fopen() at all - [man]file_put_contents/man is perfectly capable of creating a file if it doesn't already exist (or truncating it if it does).

                                      3. The code comment for the first assignment to $data is incorrect.

                                      4. There's really no need to create an extra variable $data at all.

                                      5. It might be more user-friendly (and just better practice) if you check the return value of [man]file_put_contents/man to make sure it was successful; if it wasn't, there's little sense in trying to output an <img> tag to the client that points to the file you tried and failed to create.

                                      6. If you're going to be re-generating this image file every time, what's the point in doing it at all? Why didn't you just leave the original implementation of an <img> tag with inline base64 encoded data?

                                        bradgrafelman wrote:

                                        If you're going to be re-generating this image file every time, what's the point in doing it at all? Why didn't you just leave the original implementation of an <img> tag with inline base64 encoded data?

                                        This is what I was wondering: without knowing what the problem being solved is supposed to be, it's difficult to judge the solution.