Jump to content

Image Resize On the Fly


The Little Guy

Recommended Posts

Anyone know why this isn't working?  I can not figure it out. It was working at one point, I don't think I did anything to it, and now it doesn't work.

 

When I do This on my page, All it does is print the alt text.

<img alt="image" src="resize.php?image_id=<?php echo $_GET['image_id'];?>&percent=<?php echo $_GET['percent']; ?>">

 

 

Resize.php:

<?php
// The file
session_start();
$img_id = $_GET['image_id'];
include"db.php";
$img = mysql_query("SELECT * FROM files where file_id='$img_id'")or die(mysql_error());
$imgs = mysql_fetch_array($img);
$filename = "users/".$_SESSION['user']."/".$imgs['file_name'];

$percent = $_GET['percent'];
switch($percent){
case ".25";
	$percent = .25;
break;
case ".50";
	$percent = .50;
break;
case ".75";
	$percent = .75;
break;
case "1";
	$percent = 1;
break;
default:
	$size = GetImageSize($filename);
	$width = $size[0];
	if($width < 200){
		$percent = 1;
	}else{
		$percent = .5;
	}
break;
}

// Content type
if(getext($filename)=='.jpg'){
header('Content-type: image/jpeg');
}elseif(getext($filename)=='.gif'){
header('Content-type: image/gif');
}elseif(getext($filename)=='.png'){
header('Content-type: image/png');
}

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);

if(getext($filename)=='.jpg'){
$source = imagecreatefromjpeg($filename);
}elseif(getext($filename)=='.gif'){
$source = imagecreatefromgif($filename);
}elseif(getext($filename)=='.png'){
$source = imagecreatefrompng($filename);
$alpha = imagealphablending($source, true);
imagesavealpha($alpha, true);
}
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
if(getext($filename)=='.jpg'){
imagejpeg($thumb);
}elseif(getext($filename)=='.gif'){
imagegif($thumb);
}elseif(getext($filename)=='.png'){
imagepng($thumb);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/44189-image-resize-on-the-fly/
Share on other sites

Hummmmmm

 

OK hate me but still please try this

 

add this

 

<?php

function getext()
{
return ".jpg";
}

?>

 

and test a jpg file

 

from my server (linking to yours without the database of course)

http://www.madtechiesupport.com/test3.php?user=ryan&image_id=img_23&percent=.75

 

ok you have a problem in the db.php then,

 

 

only works with jpg's but its only a test as well..

 

here's my link

www.madtechiesupport.com/test3.php?user=ryan&image_id=img_23&percent=.75

 

heres the code

<?php


function getext()
{
return ".jpg";
}
// The file
session_start();
$img_id = $_GET['image_id'];
$user = $_GET['user'];
/*include"db.php";
$img = mysql_query("SELECT * FROM files where file_id='$img_id'")or die(mysql_error());
$imgs = mysql_fetch_array($img);
$filename = "users/".$_SESSION['user']."/".$imgs['file_name'];*/
$filename = "http://tzfiles.com/users/$user/$img_id.jpg";

$percent = $_GET['percent'];
switch($percent){
case ".25";
	$percent = .25;
break;
case ".50";
	$percent = .50;
break;
case ".75";
	$percent = .75;
break;
case "1";
	$percent = 1;
break;
default:
	$size = GetImageSize($filename);
	$width = $size[0];
	if($width < 200){
		$percent = 1;
	}else{
		$percent = .5;
	}
break;
}

// Content type
if(getext($filename)=='.jpg'){
header('Content-type: image/jpeg');
}elseif(getext($filename)=='.gif'){
header('Content-type: image/gif');
}elseif(getext($filename)=='.png'){
header('Content-type: image/png');
}

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);

if(getext($filename)=='.jpg'){
$source = imagecreatefromjpeg($filename);
}elseif(getext($filename)=='.gif'){
$source = imagecreatefromgif($filename);
}elseif(getext($filename)=='.png'){
$source = imagecreatefrompng($filename);
$alpha = imagealphablending($source, true);
imagesavealpha($alpha, true);
}
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
if(getext($filename)=='.jpg'){
imagejpeg($thumb);
}elseif(getext($filename)=='.gif'){
imagegif($thumb);
}elseif(getext($filename)=='.png'){
imagepng($thumb);
}
?>

that didn't work...

 

I realized that If I view the source, I get this:

 

 

 

 

<br />

<b>Warning</b>:  getimagesize() [<a href='function.getimagesize'>function.getimagesize</a>]: URL file-access is disabled in the server configuration in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>52</b><br />

<br />

<b>Warning</b>:  getimagesize(http://tzfiles.com/users/ryan/img_23.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>52</b><br />

 

<br />

<b>Warning</b>:  imagecreatetruecolor() [<a href='function.imagecreatetruecolor'>function.imagecreatetruecolor</a>]: Invalid image dimensions in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>57</b><br />

<br />

<b>Warning</b>:  imagecreatefromjpeg() [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: URL file-access is disabled in the server configuration in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>60</b><br />

 

<br />

<b>Warning</b>:  imagecreatefromjpeg(http://tzfiles.com/users/ryan/img_23.jpg) [<a href='function.imagecreatefromjpeg'>function.imagecreatefromjpeg</a>]: failed to open stream: no suitable wrapper could be found in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>60</b><br />

<br />

<b>Warning</b>:  imagecopyresized(): supplied argument is not a valid Image resource in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>69</b><br />

 

<br />

<b>Warning</b>:  imagejpeg(): supplied argument is not a valid Image resource in <b>/home/.marble/ryannaddy/tzfiles.com/resize.php</b> on line <b>73</b><br />

 

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.