By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,278 Members | 1,329 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,278 IT Pros & Developers. It's quick & easy.

JPG -> PNG -> crapola

P: n/a
PHP4.3.2, GD2 - I have found to my great dismay and consternation that if I
load a jpg image [imagecreatefromjpg(...)], then save it as a PNG, the
resulting PNG will actually work in a browser, but it can't be loaded again
by imagecreatefrompng(...), 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
imagecreatefromjpg() 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
Jul 17 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"dan glenn" <da********@yahoo.com> wrote in message
news:JB*****************@newssvr29.news.prodigy.co m...
PHP4.3.2, GD2 - I have found to my great dismay and consternation that if I load a jpg image [imagecreatefromjpg(...)], then save it as a PNG, the
resulting PNG will actually work in a browser, but it can't be loaded again by imagecreatefrompng(...), 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
imagecreatefromjpg() 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

Try saving it as a GD (raw) image first. ex:

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

Norm

Jul 17 '05 #2

P: n/a

"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:ku********************@twister.tampabay.rr.co m...
"dan glenn" <da********@yahoo.com> wrote in message
news:JB*****************@newssvr29.news.prodigy.co m...
PHP4.3.2, GD2 - I have found to my great dismay and consternation that if
I
load a jpg image [imagecreatefromjpg(...)], then save it as a PNG, the
resulting PNG will actually work in a browser, but it can't be loaded again
by imagecreatefrompng(...), 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
imagecreatefromjpg() 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

Try saving it as a GD (raw) image first. ex:

imagecreatefromjpg -> save gd-(raw) -> close image -> load gd-(raw) ->

save as png

Norm


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

P: n/a
"dan glenn" <da********@yahoo.com> wrote in message
news:44*****************@newssvr27.news.prodigy.co m...
Tried it. Made no difference. Strange that browsers can handle the PNG
created from a JPG but nothing else (included GD2) can!


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.
Jul 17 '05 #4

P: n/a

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:x5********************@comcast.com...
"dan glenn" <da********@yahoo.com> wrote in message
news:44*****************@newssvr27.news.prodigy.co m...
Tried it. Made no difference. Strange that browsers can handle
the PNG created from a JPG but nothing else (included GD2) can!


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.


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 imagecreatefromjpeg(), 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 IMAGELOADFROMJPEG(), 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)?
Jul 17 '05 #5

P: n/a
"dan glenn" <da********@yahoo.com> wrote in message
news:44*****************@newssvr27.news.prodigy.co m...

"Norman Peelman" <np******@cfl.rr.com> wrote in message
news:ku********************@twister.tampabay.rr.co m...
"dan glenn" <da********@yahoo.com> wrote in message
news:JB*****************@newssvr29.news.prodigy.co m...
PHP4.3.2, GD2 - I have found to my great dismay and consternation that if
I
load a jpg image [imagecreatefromjpg(...)], then save it as a PNG, the
resulting PNG will actually work in a browser, but it can't be loaded

again
by imagecreatefrompng(...), 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
imagecreatefromjpg() 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

Try saving it as a GD (raw) image first. ex:

imagecreatefromjpg -> save gd-(raw) -> close image -> load gd-(raw) ->

save
as png

Norm


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


I just tried this code and it works:

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

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

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

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

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

//imagedestroy($imgd2);

imagedestroy($imjpg);

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

imagedestroy($impng);

---

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

Jul 17 '05 #6

P: n/a

"dan glenn" <da********@yahoo.com> wrote in message
news:BV*******************@newssvr29.news.prodigy. com...

"Chung Leong" <ch***********@hotmail.com> wrote in message
news:x5********************@comcast.com...
"dan glenn" <da********@yahoo.com> wrote in message
news:44*****************@newssvr27.news.prodigy.co m...
Tried it. Made no difference. Strange that browsers can handle
the PNG created from a JPG but nothing else (included GD2) can!


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.


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 imagecreatefromjpeg(), 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 IMAGELOADFROMJPEG(), 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)?


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

This discussion thread is closed

Replies have been disabled for this discussion.