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 7742361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:15:25+00:00 2026-06-01T09:15:25+00:00

I want to upload and resize pictures with different extensions. The php crops the

  • 0

I want to upload and resize pictures with different extensions. The php crops the biggest possible square from the center of the original pic, then saves it in 360*360 pixels.

The code works fine with jpeg files, but with gif, bmp and png I get a corrupted file with 33 Byte size.

Here’s most of the code:

$file_temp = $_FILES["pic"]["tmp_name"];
list ($width, $height, $type) = getimagesize ($file_temp);

$picture_name = "... a name.ext ...";
$upload = "... some dir/$picture_name";



if (move_uploaded_file($file_temp, "$upload"))
{



    //switches content-type and calls the imagecreatefrom... function
    if ($type == 1)
    {
        header ('Content-Type: image/gif');
        $image = imagecreatefromgif($upload);
    }
    elseif ($type == 2)
    {
        header ('Content-Type: image/jpeg');
        $image = imagecreatefromjpeg($upload);
    }
    elseif ($type == 3)
    {
        header ('Content-Type: image/png');
        $image = imagecreatefrompng($upload);
    }
    else
    {
        header ('Content-Type: image/x-ms-bmp');
        $image = imagecreatefromwbmp($upload);
    }


    $image_p = imagecreatetruecolor(360, 360);




    //this code below should preserve transparency but I couldn't try it out for now...

    if($type==1 or $type==3)
    {
        imagecolortransparent($image_p, imagecolorallocatealpha($image_p, 0, 0, 0, 127));
        imagealphablending($image_p, true);
        imagesavealpha($image_p, true);
    }





    //this part is for cropping
    $x=0;
    $y=0;

    if ($width > $height)
    {
        $x= ($width - $height)/2;
        $width = $height;
    }
    else
    {
        $y = ($height - $width)/2;
        $height = $width;
    }





    imagecopyresampled ($image_p, $image, 0, 0, $x, $y, 360, 360, $width, $height);
    if ($type == 1)
        imagegif ($image_p, $upload, 80);
    elseif ($type == 2)
        imagejpeg ($image_p, $upload, 80);
    elseif ($type == 3)
        imagepng ($image_p, $upload, 80);
    else
        imagewbmp ($image_p, $upload, 80);
}

So, only jpeg files are processed correctly, gif, png and bmp files aren’t. I’m out of ideas…
Thanks in advance!

  • 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-06-01T09:15:26+00:00Added an answer on June 1, 2026 at 9:15 am

    Your PHP may not be compiled with support for those formats. Run a phpinfo() and inspect the output for something like this:

    GD Support => enabled
    GD Version => bundled (2.0.34 compatible)
    GIF Read Support => enabled
    GIF Create Support => enabled
    PNG Support => enabled
    libPNG Version => 1.2.10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to upload an image from disk, resize it, and then upload it
I want to upload and store video files to my server using PHP. Could
I want to upload picture from my_form in jQuery, I tried submit() function it
I want to create a gallery of pictures for my website and upload those
I want to create a gallery of pictures for my website and upload those
I want to build an upload applet / desktop client that can resize -
I am using image upload and resize script from someones blog. It stores the
I upload images with a php script and I want to be able to
i want to upload the sound file (.ogg) in server. But it should write
I want to upload upload up to 100 MB to 1GB file onto sharepoint

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.