473,383 Members | 1,725 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

JPG -> PNG -> crapola

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
6 1778
"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

"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
"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

"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
"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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: bissatch | last post by:
Hi, I am currently writing a simple PHP program that uses an XML file to output rows for a 'Whats New' page. Once written, I will only require updating the XML file and any pages that use the...
4
by: Andrzej Wegrzyn | last post by:
Hi, I had a portal that worked before, and over 5 months period JavaScript errors started to show up on all forms where I have datagrids. Using: IE 6.0, WIN XP, IIS 5.1, Framework 1.1 ...
2
by: mit | last post by:
Hello friends , Here i have problem. I want to make the online job web site .But i donts know much about asp.net .so if any body provide me suggestion to how to create online resume database...
4
by: David Bargna | last post by:
Hi I have a problem, I have a string which needs to be converted to a byte array, then have the string representation of this array stored in an AD attribute. This string attribute then has to...
0
by: Eric | last post by:
Visual C++ 2005 Express MVP's and experience programmer's only please!... I need to get the number of lines in a textbox so I can insert them into a listview. The text comes from my database...
5
by: John Nagle | last post by:
This, which is from a real web site, went into BeautifulSoup: <param name="movie" value="/images/offersBanners/sw04.swf?binfot=We offer fantastic rates for selected weeks or days!!&blinkt=Click...
0
by: Katharine Meyers | last post by:
Don't you sometimes call tree's bark brown esp when you get mad, but why sometiems people say the tree has Germs ? Are they the same or different ? I can tell you that you aren't a racist, just...
1
by: biglork150 | last post by:
in search top dpwn bottom up what differnce do it make in between espially the outcome ? thanks
2
by: sf | last post by:
Hundsome Money Online Guaranteed payment month after month · Work part time or full time as you like . Make quick good cash working 2 to 3 hours a day . Work anywhere from home/ office without...
0
by: reema | last post by:
EJB Interview Questions http://interviewdoor.com/technical/EJB-Interview-Questions.htm CSS Interview Questions http://interviewdoor.com/technical/CSS-Interview-Questions.htm C Interview Questions...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.