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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:39+00:00 2026-05-20T05:13:39+00:00

I am developing a website in PHP that let the user to upload images

  • 0

I am developing a website in PHP that let the user to upload images and then let him to decide how the image should be using jQuery – PHP integeration to select the area that wanted to be the picture and then click the crop button to crop it and save it.

The problem that I am facing is that not all images type are good to crop and save so I noticed that the easy solution for it to convert the image to JPG and then let the user to crop it because it’s the easy way to do it in JPG format.

How I can do it?

Is this the best solution for images types problem?

EDIT:

I am using this code to crop images and it’s not wroking in PNG format and also limited to 3 ext.

$path_parts = pathinfo("../images/DVDs/".$_POST['logo_file']);
        if ($path_parts['extension'] == "png") {

                $src = imagecreatefrompng("../images/DVDs/".$_POST['logo_file']);

                        $tmp = imagecreatetruecolor(350, 494);
                        imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
                        imagepng($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
            } else if ($path_parts['extension'] == "jpg" || $path_parts['extension'] == "jpeg") {

                        $src = imagecreatefromjpeg("../images/DVDs/".$_POST['logo_file']);

                        $tmp = imagecreatetruecolor(350, 494);
                        imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
                        imagejpeg($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
                } else if ($path_parts['extension'] == "gif") {

                        $src = imagecreatefromgif("../images/DVDs/".$_POST['logo_file']);

                        $tmp = imagecreatetruecolor(350, 494);
                        imagecopyresampled($tmp, $src, 0,0,$_POST['x'],$_POST['y'],350,494,$_POST['w'],$_POST['h']);
                        imagegif($tmp, "../images/DVDs/$filename".'t_'.$_POST['logo_file'],100);
                    }

I want to convert images to JPG format because it’s the easiest to convert without any problem.

  • 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-20T05:13:40+00:00Added an answer on May 20, 2026 at 5:13 am

    Maybe it’s not working with PNG because PNG only supports compression levels 0 to 9.

    I’d also rather modify the behaviour based on MIME type, not extension. And I guess you’re checking your POST user input before using it in code 😉

    Here’s my variant of the code:

    $path = "../images/DVDs/";
    
    $img = $path . $_POST['logo_file'];
    
    if (($img_info = getimagesize($img)) === FALSE)
      die("Image not found or not an image");
    
    
    switch ($img_info[2]) {
      case IMAGETYPE_GIF  : $src = imagecreatefromgif($img);  break;
      case IMAGETYPE_JPEG : $src = imagecreatefromjpeg($img); break;
      case IMAGETYPE_PNG  : $src = imagecreatefrompng($img);  break;
      default : die("Unknown filetype");
    }
    
    $tmp = imagecreatetruecolor(350, 494);
    imagecopyresampled($tmp, $src, 0, 0, intval($_POST['x']), intval($_POST['y']),
                       350, 494, intval($_POST['w']), intval($_POST['h']));
    
    
    $thumb = $path . pathinfo($img, PATHINFO_FILENAME) . "_thumb";
    switch ($img_info[2]) {
      case IMAGETYPE_GIF  : imagegif($tmp,  $thumb . '.gif');      break;
      case IMAGETYPE_JPEG : imagejpeg($tmp, $thumb . '.jpg', 100); break;
      case IMAGETYPE_PNG  : imagepng($tmp,  $thumb . '.png', 9);   break;
      default : die("Unknown filetype");
    }
    

    For every filetype you want supported, you only have to add two lines of code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a website using PHP. I use Javascript/jquery to control/regulate user input.
I'm developing a website using PHP+Ajax. I have to fire a ajax request that
I am developing a website using ATK4, a php framework with jquery . I
I'm developing a PHP website that uses url routing. I'd like the site to
I'm developing a website in PHP and I have large JS files that I
I'm developing a website in PHP and I'd like to give the user to
I am developing a website using CodeIgniter and PHP. Some of my friends suggest
I'm currently developing a website which stores bookmarks in a MySQL database using PHP
I am developing a website using PHP and Apache. I wanna turn my URLs
I'm developing a website using PHP. My .htaccess has this rewrite rule: RewriteEngine On

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.