Jump to content

Image Resize


SieRobin

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.
Link to comment
https://forums.phpfreaks.com/topic/14402-image-resize/
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.