Jump to content

Recommended Posts

Posted

Looking for a solution that I can place into my PHP pages that enables someone uploading an image file and also resizes that file to my desired sizes ... one a thumbnail, and two a larger image size. Any suggestions on what would work? Prefer a packaged solution that I could plug into my PHP pages, or a Java applet.

Posted

Been browsing several. I am actually looking for something a bit more robust than scripts such as an off the shelf solution. Will keep looking and if anything comes to mind please don't hesitate to send up a flag.

 

Thanx and have a wonderful Thanksgiving!

Posted

Thanx much for your reply. The transparency side of things shouldn't be too much of an issue for the route we're taking, but if it does become so I'll be back in touch.

Posted (edited)

Quick function for you (assuming you only want jpg images).

 

>function image_Resize($source, $newwidth, $newHeight, $fileDestination, $newName)
{
 $size = @getimagesize($source);
 if ($size[0] > $newWidth) 
 {
$newImgHeight = ($newWidth / $size[0]) * $size[1];
$newImgWidth = $newWidth;
if ($newImgHeight > $newHeight) 
{
  $newImgWidth = ($newHeight / $newImgHeight) * $newImgWidth;
  $newImgHeight = $newHeight;
}
 } 
 elseif ($size[1] > $newHeight) 
 {
$newImgWidth = ($newHeight / $size[1]) * $size[0];
$newImgHeight = $newHeight;
if ($newImgWidth > $newWidth) 
{
  $newImgHeight = ($newWidth / $newImgWidth) * $newImgHeight;
  $newImgWidth = $newWidth;
}
 } 
 else 
 {
$newImgWidth = $size[0];
$newImgHeight = $size[1];
 }
 $newImgWidth = round($newImgWidth);
 $newImgHeight = round($newImgHeight);
 $im = imagecreatefromjpeg($source);
 $new_im = imagecreatetruecolor($newImgWidth,$newImgHeight);
 imagecopyresized($new_im,$im,0,0,0,0,$newImgWidth,$newImgHeight,$size[0],$size[1]);
 imagejpeg($new_im,$fileDestination.'/'.$newName,90);  // Have set quality to 90 although 80 produces acceptible quality and smaller files.
 imagedestroy($new_im);
}

 

Just use that to create the resized copy and once you have made your thumbnail and other two images just use unlink($image) to delete the uploaded image.

 

Oh yeah you will probably have to move the file from the temporary upload folder to one on your site before you can do anything with it.

Edited by carbonize

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...