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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.