Convert png files extensions to jpg

Discussion in 'PHP' started by rhoula, Apr 28, 2014.

  1. #1
    I have over 6000 image files that I need to change the extensions from .png to .jpg

    If you have a PHP script that can do this or know of a script I could use please help.

    Thank you in advance
     
    rhoula, Apr 28, 2014 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    You know that changing a file-extension doesn't actually do anything to the file, right? It'll still be .png-files. So, good questions to ask would be "why?". Why do you need to change the extensions? If it's for uploading, you might want to test with one file first, just to see if it will upload, since if the uploader is limited to .jpg-files, and coded properly, changing the file-extension won't do anything...
     
    PoPSiCLe, Apr 28, 2014 IP
  3. catmmo

    catmmo Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    23
    #3
    Google will help you https://www.google.com/#q=convert%20png%20to%20jpg%20with%20php
    I see many results from StackOverflow when have many PHP experts.
     
    catmmo, Apr 28, 2014 IP
  4. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #4
    ...and if you just need it to save your site's bandwidth,
    perhaps a desktop-software like Irfanview is the better tool for this bulk conversion.
     
    hdewantara, Apr 28, 2014 IP
  5. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #5
    Thank you for taking the time to write back. Actually I do need the files to stay .png The reason why I want to change them to jpg is mainly for mobile devices to be able to view them, I have a window phone and a kindle that do not show the images.
     
    rhoula, Apr 29, 2014 IP
  6. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #6
    I did try google search before I came here. I found hundreds of links but none of them worked. There are at least a couple dozens from Stackoverflow that I already tried but did not work for many reasons. Plus on top of everything I want to ask for help so other people like me will be able to use DP like we used to do before to exchange information, help and teach each other.
     
    rhoula, Apr 29, 2014 IP
  7. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #7
    @hdewantara I came across Irfanview but was a little skeptic about it. The site did not seem to be very popular so I didn't want to risk installing the software on my computer. Thank you very much for your help
     
    rhoula, Apr 29, 2014 IP
  8. hdewantara

    hdewantara Well-Known Member

    Messages:
    540
    Likes Received:
    47
    Best Answers:
    25
    Trophy Points:
    155
    #8
    Well, it's not for a Mac user I guess but is among the top 30... according to CNET's Most Popular Downloads for Windows. And I've been using it for years for "lightweight conversion" w/o any major problems.
     
    hdewantara, Apr 29, 2014 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Uhm... Windows Phone and most other tablets and phones (regardless of OS) should be able to view .png-files. I do not know about the Kindle, mind - I don't have one. Depending on the Kindle, it seems that image-formats are generally poorly supported on the Kindle (which is sort of natural, as it's not meant as an image-viewer).
     
    PoPSiCLe, Apr 30, 2014 IP
  10. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #10
    BTW, Irfanview is one of the oldest and most reliable image-programs for the PC. Along with ACDSee and FastStone Image Viewer, they're among the best for converting, viewing and minor editing out there.
     
    PoPSiCLe, Apr 30, 2014 IP
  11. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #11
    Yeah, PNG should work on anything made after 1998... if they're not 'working' there's probably something else wrong with them; like being too large for the mobile device's memory, or being improperly encoded.

    Could you provide a link to an example page where you are having issues? I've got the feeling that PNG is NOT your problem. (hell, even IE 4 supported PNG so long as you didn't need alpha transparency).
     
    deathshadow, Apr 30, 2014 IP
  12. TIEro

    TIEro Active Member

    Messages:
    741
    Likes Received:
    177
    Best Answers:
    5
    Trophy Points:
    70
    #12
    Just as a side-note, only changing the file extension will not make it possible for an application to decode the contents. That's like labelling a French book "Written in English" but not translating it.
     
    TIEro, Apr 30, 2014 IP
  13. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #13
    Believe it or not it did work when I changed just the extension. Please check out this link for more details:

    http://muslimsintheus.com/Quran/pagination/index2.php?currentpage=800

    Thank you
     
    rhoula, Apr 30, 2014 IP
  14. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #14
    What browser? I'm not getting that center image here at all in IE, Opera or Chrome... it IS showing up in FF however which is actually WRONG -- as just renaming the file doesn't MAKE it that type of file. You actually have to convert it...

    ... and given most mobile browsers use either Presto (legacy Opera) or Webkit/Blink (safari, chrome, new useless crippled Opera); well there's your problem.
     
    deathshadow, Apr 30, 2014 IP
  15. TIEro

    TIEro Active Member

    Messages:
    741
    Likes Received:
    177
    Best Answers:
    5
    Trophy Points:
    70
    #15
    That's because your computer is smart enough to figure out that the extension is wrong, identify the file type by its header and use the right decoder. Which is absolutely not guaranteed to work on any other device and doesn't mean the file is a JPG - it's still a PNG and being treated as a PNG... your computer just doesn't bother to tell you. :)
     
    TIEro, Apr 30, 2014 IP
  16. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #16
    I'm using Chrome and the image is showing on my computer. I even tried it on my friend's computer and it worked.

    for the mobile browser, I'm using Incognito Browser.

    Back to the main subject if you don't mind :) anyone know of a php script that can change extension in bulk.

    Thank you so much
     
    rhoula, Apr 30, 2014 IP
  17. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #17
    THAT IS the main subject, as what you are trying to do is just going to make things WORSE, likely isn't actually what's wrong, and generally speaking, you are trying to do something you should NEVER BE DOING IN THE FIRST BLASTED PLACE -- changing the file extension but not actually changing what the file IS.

    Simply renaming jpg to png or vice-versa without ACTUALLY CHANGING THE FILE FORMAT is half-assed halwit BULL that to be frank, that you are even trying to do it probably means you don't know enough about files, filesystems, programming, or the web to be managing a website in the first place!

    Sorry if that's harsh, but that's the truth.

    Of course, the laugh being that if you REALLY want to do this regardless of how badly it is going to screw the pooch, this is a shell / command line tool's job, not PHP.

    Open up your terminal/shell/ssh session (whichever is appropriate)

    Windows PowerShell / command / DOS:
    rename *.png *.jpg

    BASH (*nix)
    rn ./*png ./*.jpg

    Though again, you REALLY have NO BUSINESS DOING THIS!!! (as evidenced by it NOT working here worth **** in anything but FF). If your "PNG" files aren't working, there's something wrong with them... like maybe you have jpegs that are labelled png? Have you already screwed around with the wrong extensions so badly that you have a inconsistent mess?
     
    deathshadow, Apr 30, 2014 IP
  18. rhoula

    rhoula Well-Known Member

    Messages:
    875
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    145
    #18
    Wow...
     
    rhoula, Apr 30, 2014 IP
  19. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #19
    Actually, it doesn't work. If I click "show image" and then "save image", it downloads as a png-file. Which it should, since that's what it is. Chrome browser on Android
     
    PoPSiCLe, May 1, 2014 IP