JPG -> PNG -> crapola

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dan glenn

    JPG -> PNG -> crapola

    PHP4.3.2, GD2 - I have found to my great dismay and consternation that if I
    load a jpg image [imagecreatefrom jpg(...)], then save it as a PNG, the
    resulting PNG will actually work in a browser, but it can't be loaded again
    by imagecreatefrom png(...), and if I try to open it with a graphics program,
    like Paint Shop Pro, it tells me that it is no a legitament PNG file and
    refuses to load it.

    Likewise, if I start with a legit PNG (works with PSP), and save as a jpg,
    the jpg will work in a browser, but can't be loaded again with
    imagecreatefrom jpg() or with PSP.

    I was under the impression I could load from one type and save as another
    type as long as I didn't try to do something stupid like go from a truecolor
    image to a palette-based image, or vice-versa.

    Do I have to give up on change types this way???
    -dg


  • Norman Peelman

    #2
    Re: JPG -> PNG -> crapola

    "dan glenn" <dan_danboy@yah oo.com> wrote in message
    news:JBaDc.7844 6$5q.3109@newss vr29.news.prodi gy.com...[color=blue]
    > PHP4.3.2, GD2 - I have found to my great dismay and consternation that if[/color]
    I[color=blue]
    > load a jpg image [imagecreatefrom jpg(...)], then save it as a PNG, the
    > resulting PNG will actually work in a browser, but it can't be loaded[/color]
    again[color=blue]
    > by imagecreatefrom png(...), and if I try to open it with a graphics[/color]
    program,[color=blue]
    > like Paint Shop Pro, it tells me that it is no a legitament PNG file and
    > refuses to load it.
    >
    > Likewise, if I start with a legit PNG (works with PSP), and save as a jpg,
    > the jpg will work in a browser, but can't be loaded again with
    > imagecreatefrom jpg() or with PSP.
    >
    > I was under the impression I could load from one type and save as another
    > type as long as I didn't try to do something stupid like go from a[/color]
    truecolor[color=blue]
    > image to a palette-based image, or vice-versa.
    >
    > Do I have to give up on change types this way???
    > -dg
    >
    >
    >[/color]
    Try saving it as a GD (raw) image first. ex:

    imagecreatefrom jpg -> save gd-(raw) -> close image -> load gd-(raw) -> save
    as png

    Norm



    Comment

    • dan glenn

      #3
      Re: JPG -&gt; PNG -&gt; crapola


      "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
      news:kunDc.1579 09$Ol3.95932@tw ister.tampabay. rr.com...[color=blue]
      > "dan glenn" <dan_danboy@yah oo.com> wrote in message
      > news:JBaDc.7844 6$5q.3109@newss vr29.news.prodi gy.com...[color=green]
      > > PHP4.3.2, GD2 - I have found to my great dismay and consternation that[/color][/color]
      if[color=blue]
      > I[color=green]
      > > load a jpg image [imagecreatefrom jpg(...)], then save it as a PNG, the
      > > resulting PNG will actually work in a browser, but it can't be loaded[/color]
      > again[color=green]
      > > by imagecreatefrom png(...), and if I try to open it with a graphics[/color]
      > program,[color=green]
      > > like Paint Shop Pro, it tells me that it is no a legitament PNG file and
      > > refuses to load it.
      > >
      > > Likewise, if I start with a legit PNG (works with PSP), and save as a[/color][/color]
      jpg,[color=blue][color=green]
      > > the jpg will work in a browser, but can't be loaded again with
      > > imagecreatefrom jpg() or with PSP.
      > >
      > > I was under the impression I could load from one type and save as[/color][/color]
      another[color=blue][color=green]
      > > type as long as I didn't try to do something stupid like go from a[/color]
      > truecolor[color=green]
      > > image to a palette-based image, or vice-versa.
      > >
      > > Do I have to give up on change types this way???
      > > -dg
      > >
      > >
      > >[/color]
      > Try saving it as a GD (raw) image first. ex:
      >
      > imagecreatefrom jpg -> save gd-(raw) -> close image -> load gd-(raw) ->[/color]
      save[color=blue]
      > as png
      >
      > Norm[/color]

      Tried it. Made no difference. Strange that browsers can handle the PNG
      created from a JPG but nothing else (included GD2) can!


      Comment

      • Chung Leong

        #4
        Re: JPG -&gt; PNG -&gt; crapola

        "dan glenn" <dan_danboy@yah oo.com> wrote in message
        news:44sDc.3099 $Qh5.1995@newss vr27.news.prodi gy.com...[color=blue]
        > Tried it. Made no difference. Strange that browsers can handle the PNG
        > created from a JPG but nothing else (included GD2) can!
        >[/color]

        Make sure the file in question is actually of the said format. IE does data
        sniffing, so that a file with the wrong extension would open correctly.
        Right click on the image and check the properties.


        Comment

        • dan glenn

          #5
          Re: JPG -&gt; PNG -&gt; crapola


          "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
          news:x5CdnUpluo 1z30LdRVn-uw@comcast.com. ..[color=blue]
          > "dan glenn" <dan_danboy@yah oo.com> wrote in message
          > news:44sDc.3099 $Qh5.1995@newss vr27.news.prodi gy.com...[color=green]
          > > Tried it. Made no difference. Strange that browsers can handle
          > > the PNG created from a JPG but nothing else (included GD2) can!
          > >[/color]
          >
          > Make sure the file in question is actually of the said format.
          > IE does data sniffing, so that a file with the wrong extension
          > would open correctly. Right click on the image and check the
          > properties.[/color]

          WOW. You're absolutely correct. Right-clicking and checking
          properties doesn't tell me the 'true' format - it just reports
          whatever the extension says. But I found that if I renamed the
          newly-created PNG to have extension .JPG, it CAN be loaded again
          via imagecreatefrom jpeg(), which means that it truly is a JPG.

          So it would seem that IMAGEPNG() is just the same as IMAGEJPEG()
          if the original image was loaded by IMAGELOADFROMJP EG(), which
          is saying IMAGEPNG() will save as a JPG, which is a bit bizaar,
          I think! The manual never explicitly says this. Maybe the idea
          of loading from one type and saving to another type is 'crazy'
          and they didn't think they had to say this in the manual?

          Anyway, I GIVE UP! I'm going to try an use ImageMagik, or something
          like that to transform from one format to another, which brings me
          to another question I hope you may be able to help me with: my web
          host does not offer telnet access. How can I get ImageMagik (or
          anything like this, for that matter), installed so I can use it?
          Only source files are available for unix ImageMagik, and that means
          it must be compiled on the server machine itself, which I (seemingly)
          can't do, since I don't have that kind of access.

          Am I missing something in this analysis (I am not at all acquainted
          that much with UNIX)?


          Comment

          • Norman Peelman

            #6
            Re: JPG -&gt; PNG -&gt; crapola

            "dan glenn" <dan_danboy@yah oo.com> wrote in message
            news:44sDc.3099 $Qh5.1995@newss vr27.news.prodi gy.com...[color=blue]
            >
            > "Norman Peelman" <npeelman@cfl.r r.com> wrote in message
            > news:kunDc.1579 09$Ol3.95932@tw ister.tampabay. rr.com...[color=green]
            > > "dan glenn" <dan_danboy@yah oo.com> wrote in message
            > > news:JBaDc.7844 6$5q.3109@newss vr29.news.prodi gy.com...[color=darkred]
            > > > PHP4.3.2, GD2 - I have found to my great dismay and consternation that[/color][/color]
            > if[color=green]
            > > I[color=darkred]
            > > > load a jpg image [imagecreatefrom jpg(...)], then save it as a PNG, the
            > > > resulting PNG will actually work in a browser, but it can't be loaded[/color]
            > > again[color=darkred]
            > > > by imagecreatefrom png(...), and if I try to open it with a graphics[/color]
            > > program,[color=darkred]
            > > > like Paint Shop Pro, it tells me that it is no a legitament PNG file[/color][/color][/color]
            and[color=blue][color=green][color=darkred]
            > > > refuses to load it.
            > > >
            > > > Likewise, if I start with a legit PNG (works with PSP), and save as a[/color][/color]
            > jpg,[color=green][color=darkred]
            > > > the jpg will work in a browser, but can't be loaded again with
            > > > imagecreatefrom jpg() or with PSP.
            > > >
            > > > I was under the impression I could load from one type and save as[/color][/color]
            > another[color=green][color=darkred]
            > > > type as long as I didn't try to do something stupid like go from a[/color]
            > > truecolor[color=darkred]
            > > > image to a palette-based image, or vice-versa.
            > > >
            > > > Do I have to give up on change types this way???
            > > > -dg
            > > >
            > > >
            > > >[/color]
            > > Try saving it as a GD (raw) image first. ex:
            > >
            > > imagecreatefrom jpg -> save gd-(raw) -> close image -> load gd-(raw) ->[/color]
            > save[color=green]
            > > as png
            > >
            > > Norm[/color]
            >
            > Tried it. Made no difference. Strange that browsers can handle the PNG
            > created from a JPG but nothing else (included GD2) can!
            >
            >
            >[/color]

            I just tried this code and it works:

            $imjpg = imagecreatefrom jpeg("path:/to/your.jpg");
            // load from jpg file

            //header("Content-type: image/jpg");
            //imagejpeg($imjp g);

            //imagegd2($imjpg ,"path:/to/your.gd");
            //imagedestroy($i mjpg);

            //$imgd2 = imagecreatefrom gd2("path:/to/your.gd");
            //imagepng($imgd2 ,"path:/to/your.png");

            imagepng($imjpg ,"path:/to/your.png");
            // save to png file

            //imagedestroy($i mgd2);

            imagedestroy($i mjpg);

            // open new png file and display
            $impng = imagecreatefrom png("path:/to/your.png");
            header("Content-type: image/x-png");
            imagepng($impng );

            imagedestroy($i mpng);

            ---

            As you can see I did some testing and found that there are some cache
            issues that make the browser (in this case Opera7) think that the image is
            still a JPEG after the second (PNG) image is sent to it. By commenting out
            everything but the loading, conversion, and final display, it works
            perfectly.

            Norm



            Comment

            • Chung Leong

              #7
              Re: JPG -&gt; PNG -&gt; crapola


              "dan glenn" <dan_danboy@yah oo.com> wrote in message
              news:BVQDc.7890 3$0d3.22725@new ssvr29.news.pro digy.com...[color=blue]
              >
              > "Chung Leong" <chernyshevsky@ hotmail.com> wrote in message
              > news:x5CdnUpluo 1z30LdRVn-uw@comcast.com. ..[color=green]
              > > "dan glenn" <dan_danboy@yah oo.com> wrote in message
              > > news:44sDc.3099 $Qh5.1995@newss vr27.news.prodi gy.com...[color=darkred]
              > > > Tried it. Made no difference. Strange that browsers can handle
              > > > the PNG created from a JPG but nothing else (included GD2) can!
              > > >[/color]
              > >
              > > Make sure the file in question is actually of the said format.
              > > IE does data sniffing, so that a file with the wrong extension
              > > would open correctly. Right click on the image and check the
              > > properties.[/color]
              >
              > WOW. You're absolutely correct. Right-clicking and checking
              > properties doesn't tell me the 'true' format - it just reports
              > whatever the extension says. But I found that if I renamed the
              > newly-created PNG to have extension .JPG, it CAN be loaded again
              > via imagecreatefrom jpeg(), which means that it truly is a JPG.
              >
              > So it would seem that IMAGEPNG() is just the same as IMAGEJPEG()
              > if the original image was loaded by IMAGELOADFROMJP EG(), which
              > is saying IMAGEPNG() will save as a JPG, which is a bit bizaar,
              > I think! The manual never explicitly says this. Maybe the idea
              > of loading from one type and saving to another type is 'crazy'
              > and they didn't think they had to say this in the manual?
              >
              > Anyway, I GIVE UP! I'm going to try an use ImageMagik, or something
              > like that to transform from one format to another, which brings me
              > to another question I hope you may be able to help me with: my web
              > host does not offer telnet access. How can I get ImageMagik (or
              > anything like this, for that matter), installed so I can use it?
              > Only source files are available for unix ImageMagik, and that means
              > it must be compiled on the server machine itself, which I (seemingly)
              > can't do, since I don't have that kind of access.
              >
              > Am I missing something in this analysis (I am not at all acquainted
              > that much with UNIX)?[/color]

              Sounds like you have a busted built of PHP or there's something wrong with
              your logic somewhere. Please post the code in question.


              Comment

              Working...