Jump to content

Archived

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

SieRobin

Image Resize

Recommended Posts

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?

[code]<?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();
}
?>[/code]

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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

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.