Jump to content

Image resize problem


genista

Recommended Posts

Hi,

 

I am trying to resize an image on upload the problem is that I think I am over complicating it by running a seperate function for each file type, added to the fact that I get an error which I will explain after the following code:

 

if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) { 
if (($HTTP_POST_FILES['userfile']['type'])=="image/gif"){
   function resizeImage($HTTP_POST_FILES['userfile']['type']))
   {
   
      $imgSize = getimagesize($HTTP_POST_FILES['userfile']['type']);
      $imgWidth = $imgSize[0];
      $imgHeight = $imgSize[1];
      $newWidth = "60";
      $newHeight = "60";
      
      $source = imagecreatefromjpeg($HTTP_POST_FILES['userfile']['type']);
      $thumb1 = imagecreatetruecolor($newWidth, $newHeight);
      
      imagecopyresized($thumb1, $source, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgHeight);
      header('Content-type: image/jpeg'); // <-- you need that!
      imagejpeg($thumb1);
   
   }
}
//After this point rename file and insert value to database.

 

As you can see I will need to run this function for every file type, gif, jpeg etc and I get an error: on the following line:

 

function resizeImage($HTTP_POST_FILES['userfile']['type']))

 

:

 

Parse error: parse error, unexpected '[', expecting ')'

 

Thanks,

 

 

G

Link to comment
https://forums.phpfreaks.com/topic/56852-image-resize-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.