Jump to content

help with my if() statement


php_beginner_83

Recommended Posts

Hi All

 

I have an If() statement and it's not returning the result I want and I can't figure out why.  I have printed values out to screen in a test program but I can't get this to work.  I really need some advice. 

 

Thanks in advance.

 

The input string will be 'images\alcatraz.jpg'

What I want to happen is, if the input string has 'images\' in front of it I want to strip that off and just use 'alcatraz.jpg'.  If it doesn't have 'images\' in front then I want to add 'thumbs\'.

This is my code..

 

header("Content-type: image/png");

$dir = "thumbs/";
$filename = $_GET['image'];
$thumbWidth = 50;
$thumbHeight = 50;

$substr = substr($filename, 0, 6);
$len = strlen($filename);

if($substr === "images")
{
$img = imagecreatefromjpeg(substr($filename, 8, $len);
}
else
{
// load image
$img = imagecreatefromjpeg($dir . $filename);
}

// get image size
$width = imagesx($img);
$height = imagesy($img);

// find wide picture
if ($width > $height)
{
$newWidth = $thumbWidth;
$newHeight = $thumbWidth * ($height/$width);
}
else
{
$newWidth = $thumbHeight * ($width/$height);
$newHeight = $thumbHeight;
}

// create temporary image
$tempImg = imagecreatetruecolor($newWidth, $newHeight);

// create the thumbnail
imagecopyresampled($tempImg, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);

// output thumbnail
imagepng($tempImg);

Link to comment
https://forums.phpfreaks.com/topic/181854-help-with-my-if-statement/
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.