Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:33:11+00:00 2026-05-26T08:33:11+00:00

I made a function to handle jpg and png files, but i get error

  • 0

I made a function to handle jpg and png files, but i get error when trying to upload a png file.

this is the function:

function createImg ($type, $src, $dst, $width, $height, $quality) {

$newImage = imagecreatetruecolor($width,$height);
if ($type == "jpg/jpeg") {  
    //imagecreatefromjpeg() returns an image identifier representing the image obtained from the given filename.
    $source = imagecreatefromjpeg($src);
}
else if ($type == "png") {
    //imagecreatefrompng() returns an image identifier representing the image obtained from the given filename.
    $source = imagecreatefrompng($src);
}
imagecopyresampled($newImage,$source,0,0,0,0,$width,$height,getWidth($src),getHeight($src));
if ($type == "jpg/jpeg") {
    //imagejpeg() creates a JPEG file from the given image. 
    imagejpeg($newImage,$dst,$quality); 
}
else if ($type == "png") {
    //imagepng() creates a PNG file from the given image. 
    imagepng($newImage,$dst,$quality);      
}
return $dst;

}

works as it should with jpg, but with png i get this error msg:

Warning: imagepng() [function.imagepng]: gd-png: fatal libpng error: zlib failed to initialize compressor — stream error in E:…\php\functions.upload.php on line 48

Warning: imagepng() [function.imagepng]: gd-png error: setjmp returns error condition in E:…\php\functions.upload.php on line 48

EDIT :

i just changed removed the imagepng(); and used only imagejpeg and it worked like this, i just want jpg files saved anyways. thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:33:11+00:00Added an answer on May 26, 2026 at 8:33 am

    The problem is because imagejpeg quality can be up to 100, whereas imagepng maximum quality is 9.
    try this

     else if ($type == "png") {
    //imagepng() creates a PNG file from the given image. 
    $q=9/100;
    $quality*=$q;
    imagepng($newImage,$dst,$quality);      
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi have made this function which is made to replicate an error that I
I made this function to verify a user's twitter credentials. Its running on two
i have made a function to add new upload and description inputs onClick. How
I made this little function from code snippets around the net. It does what
I made a function like this (no need to write the whole function here)
I want to display 404 error page for that i have made error404.php file
I've made this to call unmanaged function from C code. pCallback is a function
I made this small location class so that I can better handle address information
I made a function which displays date on the webpage,, and i uploaded the
I've made a function dump_text(std::ostream &) that dumps some text in a standard output

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.