Jump to content

Archived

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

SieRobin

Image Resize

Recommended Posts

I did view source, the IMG tag looks like this for my picture.

<img src='image.php?img=userimages/me.jpg' border='0'>

Other then that, I'm not sure what you mean, sorry :\

Share this post


Link to post
Share on other sites
Ok, you want to put debug statements into the image.php file. But those statements can't write to the screen. They should write to a file.

What type of platform are you using? Windows or Unix (linux)

Here's how I would do it:
[code]<?php
function write_debug($fp,date('Y-m-d G:i:s') . $str) {
   f write($fp,$str . "\n");
}

session_start();
$dbg = (isset($_GET['dbg']))?true:false;
if ($dbg) {
    $fp = f open('image_debug.txt','a');
    write_debug($fp,' --  Entering image.php');
    write_debug($fp,' -- $_GET --');
    write_debug($fp,print_r($_GET,true));
    f close($fp);
}
if (isset($_GET['img'])) {
// $img_name = "userimages/$pstats3[uimage]"; // <--- this statement is wrong -- my mistake sorry
   $img_name = $_GET['img'];
$max_width    = 150;
$max_height   = 150;
$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");
$src_img = imagecreatefromjpeg($img_name);
$thumb = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width-1),($new_height-1),$size[0],$size[1]);
imagejpeg($thumb);
imagedestroy($src_img);
imagedestroy($thumb);
exit();
}
?>[/code]

While I was added the debug code to your image.php I noticed what the problem is. See the comment above with the "<---" in it.

The next line is the corrected line.

If changing that line works, you don't have to put in the debugging lines.

In the debug area I had to write the file functions with a space in them.

Ken

Share this post


Link to post
Share on other sites
Just one more question, I'm pretty sure it's easy to answer.. well since the only thing the code seems to accept is JPEG is there a way to allow GIF and PNG?

Share this post


Link to post
Share on other sites
How exactly can I make it also accept GIF files and not just JPEG? Because, right now it will only display if it's in JPEG format.

Share this post


Link to post
Share on other sites
forgive me if i am wrong but i would think you would just need to modify this line

header("Content-Type: image/jpeg");

i dont know the syntax but i would make it something like this

header("Content-Type: image/jpeg/JPEG/GIF/gif/PNG/png");

does that work??

Share this post


Link to post
Share on other sites
My server is down right now but, I don't think that'd work since, it's asking it to createfromjpeg.. now if I were to put createfromgif it would allow all GIF extensions, but I can try it, never hurt to try.

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.