Jump to content


Photo

Image Resize


  • Please log in to reply
3 replies to this topic

#1 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 12 July 2006 - 06:40 PM

Ok so I have it set so your user image you chose to upload, it resizes in the forum, just so it isn't huge and makes the forum look goofy.. yet I've come across a problem I can not fix. The script resizes all JPEG images, but it won't resize PNG or GIF, which are the other extensions I'm allowing. Can someone tell me if I have a flaw in my script, because I'm just confused?

<?php
session_start();
if (isset($_GET['img'])) {
$img_name = $_GET['img'];
$file_type=$_FILES['image']['type'];
$max_width=120;
$max_height=120;
$size=getimagesize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio =($size[1] / $max_height);
if($width_ratio>=$height_ratio) 
{
   $ratio=$width_ratio;
}
else
{
   $ratio=$height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
header("Content-Type: image/jpeg, image/gif, image/png");
if ($file_type="image/pjpeg"||$file_type="image/jpeg") {
$src_img = imagecreatefromjpeg($img_name); }
elseif ($file_type="image/x-png"||$file_type="image/png") {
$src_img = imagecreatefrompng($img_name); }
elseif ($file_type="image/gif") {
$src_img = imagecreatefromgif($img_name); }
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width),($new_height),$size[0],$size[1]);
imagejpeg($thumb);
imagedestroy($src_img);
imagedestroy($thumb);
exit();
}
?>

Like I said, it resizes JPEGs just fine, and they're good to go, but the others won't work.

#2 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 12 July 2006 - 07:38 PM

Wait I don't think the file_type is working, hmmn.

#3 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 12 July 2006 - 07:55 PM

Well I figured out that I can't use $_FILES because I'm not taking it from a form or input.. therefore I can't take the type from the image.. any other ideas on how I can tell what the file type is?

#4 SieRobin

SieRobin
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts
  • LocationNew Jersey

Posted 12 July 2006 - 08:04 PM

Got it, nevermind.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users