Change the Width of a Picture


Current Image:

My Dog

Select Width Change (0 = no change, 5 = Max Change)

Width Determination:

0   1   2   3   4   5  





SLAVE CODE FOLLOWS

<?php // skinny script

$skinny $_GET['sk'];

// get the images from files
$image imagecreatefromjpeg("images/ollie.JPG");

// get sizes of original
$width_orig imagesx($image);
$height imagesy($image);

// adjust the width for the new image
$width $width_orig - ($width_orig $skinny .05);

// create a new image
$new_image imagecreatetruecolor($width$height);

// resample old to new image
imagecopyresampled($new_image$image0000$width$height$width_orig$height);

// set the header for the new image
header("Content-type: image/jpeg");
imagejpeg($new_image);
imagedestroy($new_image);

?>

 

CODE FOLLOWS

<?php
include('includes/header.php');

$self basename($_SERVER['SCRIPT_NAME']);
$step = isset($_POST['step']) ? $_POST['step'] : 1;
$skinny = isset($_POST['choice']) ? $_POST['choice'] : null;

$s 'CHECKED';

if(isset(
$_POST['choice']))
{
    
$choice $_POST['choice'];
}
else
{
    
$choice 0;    // set default here
}

?>

<h2>
    Change the Width of a Picture
</h2>

<?php

switch ($step)
{

    
// STEP 1 ----------------------

    
case 1:    //--- get the change of brightness the user wants
        
?>

        <hr>
        <p>
            Current Image:
        </p>

        <img src="images/ollie.JPG" alt="My Dog">

        <p>
            Select Width Change (0 = no change, 5 = Max Change)
        </p>

        <form action="<?php echo($self); ?>" method="post">
            <fieldset>
                <legend>Width Determination:</legend>
                <label for="choice">Width</label>
                <br><br>
                <?php
                
for ($i 0$i <= 5$i++)
                {
                    
?>

                    <input type="radio" id="choice" name="choice"
                           value="<?php echo($i); ?>"<?php if ($choice == $i) {
                        echo(
$s);
                    } 
?> > <?php echo($i); ?> &nbsp;

                    <?php
                
}
                
?>
            </fieldset>
            <br>
            <br>
            <input type="submit" name="submit" value="Submit">
            <input type="hidden" name="step" value="2">
        </form>
        <br>


        <?php
        
break;

    
// STEP 2 ----------------------

    
case 2:    //--- show the brightness

        // provide the user the opportunity to try again
        
?>

        <hr>

        <h3> Skinnyness: <?php echo($skinny);?></h3>

        <img src="skinny.php?sk=<?php echo($skinny);?> alt="My Skinny Dog">

        <br>

        <form action="<?php echo($self);?>" method="post">
            <input type="hidden" name="step" value="1">
            <input type="submit" value="Try Again">
        </form>

        <br>

        <?php
        
break;
}

// end of program
// list code for slave routine
echo('<hr><br>SLAVE CODE FOLLOWS<br><br>');
highlight_file ('skinny.php');
echo(
'<hr>');

include(
'includes/footer.php');
?>