Wrox Programmer Forums
|
BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143
This is the forum to discuss the Wrox book Beginning PHP 6, Apache, MySQL 6 Web Development by Timothy Boronczyk, Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz; ISBN: 9780470391143
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 24th, 2011, 02:27 PM
bcb bcb is offline
Registered User
 
Join Date: Mar 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7 Anyone with a working set of code?

Hi, I have just completed chapter 7 and in spite of combing through the forum and making the recommended corrections, I am not able to get the code to work completely as described in the book.

Displaying the text over the photo does not work in preview mode, but the text does appear when I save the file.

Gallery.php does not show the thumbnails and I have yet to figure out how to configure the file correctly.

To add insult to injury, the code available for download on this site for chapter 7 does not work properly.

So if anyone has completed chapter 7 and has a fully functional set of code from the chapter that they would be willing to share and post here I would appreciate it!

specifically check_image.php upload_image.html and image_effect.php and gallery.php.

Thank you
 
Old April 27th, 2011, 04:16 PM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7 Anyone with a working set of code?

Hi,
I'm struggling with the filters now, did you get them to work?
 
Old April 28th, 2011, 03:35 PM
bcb bcb is offline
Registered User
 
Join Date: Mar 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I was able to get the filters to work. I will post my code tomorrow. I am not at the computer I usually use at the moment.
 
Old April 29th, 2011, 04:19 PM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7 Anyone with a working set of code?

Ok, dont worry, I got it working. I actually got all the code working, and there were couple things to note:
1. The problem with the caption was that GDFONTPATH didnt work the way its in the book (at least in Win7), so instead of just 'arial' for $font variable I specified the path to the font file, so the code looks like this:

Code:
// Change the path to match fonts directory
putenv('GDFONTPATH=C:/Windows/Fonts');
$font = getenv('GDFONTPATH'). '/arial.ttf';
Than it was recognized correctly.

2. As for gallery, if the thumbnail exists in the $thumbdir directory, but not displayed in gallery.php, then most likely the path you specify is not correct. I did it by the book, specified relative paths and it works fine. There might be a problem in HTML code, but errors are not displayed, so I checked the code in the notepad++, its easy with the colors ;)

Let me know if it works fine for you, I'm moving to the next chapter :)
 
Old April 29th, 2011, 04:25 PM
bcb bcb is offline
Registered User
 
Join Date: Mar 2011
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 7 my best effort

Here are my 3 files. Plus Gallery.php ... they never worked as described in the book, even after following the fixes mentioned here in the forum. Hoping someone has a 100% working version of these.

check_image.php

Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
	die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die (mysql_error($db));

//change this path to match your images directory
$dir ='C:/wamp/www/moviesite/images';

//change this path to match your thumbnail directory
$thumbdir = $dir . '/thumbs';

putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';

//handle the uploaded image
if ($_POST['submit'] == 'Upload') {

//make sure the uploaded file transfer was successful
if ($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK) {
	switch ($_FILES['uploadfile'] ['error']) {
	case UPLOAD_ERR_INI_SIZE:
		die('The uploaded file exceeds the upload_max_filesize_directive ' . 'in php. ini.');
	break;
	case UPLOAD_ERR_FORM_SIZE:
		die('The uploaded file exceeds the MAX_FILE_SIZE diretive that ' . 'was specified in the HTML form.');
	break;
	case UPLOAD_ERR_PARTIAL:
		die('The uploaded file was only partially uploaded.');
		break;
	case UPLOAD_ERR_NO_FILE:
		die('No file was uploaded.');
		break;
	case UPLOAD_ERR_NO_TMP_DIR:
		die('The sierver is missing a temporary folder.');
		break;
	case UPLOAD_ERR_CANT_WRITE:
		die('The server failed to write the upladoed file to disk.');
		break;
	case UPLOAD_ERR_EXTENSION:
		die('File upload stopped by extension.');
		break;
	}
}
//get info about the image being uploaded
 $image_caption = $_POST['caption'];
 $image_username = $_POST['username'];
 $image_date = date('Y-m-d');
 list($width, $height, $type, $attr) = 	getimagesize($_FILES['uploadfile']['tmp_name']);
	
//make sure the uplaoded file is really a supported image
$error = 'The file you uploaded was not a supported filetype.';
switch ($type) {
case IMAGETYPE_GIF:
	$image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or
		die($error);
	break;
case IMAGETYPE_JPEG:
	$image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or
		die($error);
	break;
case IMAGETYPE_PNG:
	$image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or
	die($error);
     }
	
	

//insert information into image table
$query = 'INSERT INTO images
	(image_caption, image_username, image_date)
VALUES
	("' . $image_caption . '", "' . $image_username . '", "' . $image_date . '")';
$result = mysql_query($query, $db) or die (mysql_error ($db));

//retrieve the image_id that MySQL generated automatically when we inserted
//the new record
$last_id = mysql_insert_id();

//save the image to its final destination
$image_id = $last_id;
imagejpeg($image, $dir . '/' . $image_id . '.jpg');
imagedestroy($image);
} else {
//retrieve image information
$query = 'SELECT
	image_id, image_caption, image_username, image_date
FROM
	images
WHERE
	image_id = ' . $_POST['id'];
$result = mysql_query($query, $db) or die (mysql_error($db));
extract(mysql_fetch_assoc($result));

list($width, $height, $type, $attr) = getimagesize($dir . '/' .
$image_id .
	'.jpg');
}

if ($_POST['submit'] == 'Save') {
	//make sure the requested image is valid
	if (isset($_POST['id']) && ctype_digit($_POST['id']) &&
	file_exists($dir . '/' . $_POST['id'] . '.jpg')) {
	$image = imagecreatefromjpeg($dir . '/' . $_POST['id'] . '.jpg');
	}else {
		die('invalid image specified');
	}
	
	//apply the filter
$effect = (isset($_POST['effect'])) ? $_POST['effect'] : -1;
switch ($effect) {
case IMG_FILTER_NEGATE:
	imagefilter($image, IMG_FILTER_GRAYSCALE);
	break;
case IMG_FILTER_GRAYSCALE:
	imagefilter($image, IMG_FILTER_GRAYSCALE);
	break;
case IMG_FILTER_EMBOSS:
	imagefilter($image, IMG_FILTER_EMBOSS);
	break;
case IMG_FILTER_GAUSSIAN_BLUR:
	imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
	break;
}

//add the caption if requested
if (isset($_POST['emb_caption'])) {
	imagettftext($image, 12, 0, 20, 20, 0, $font, $image_caption);
}
//add the logo watermark if requested
    if (isset($_POST['emb_logo'])) {
        // determine x and y position to center watermark
        list($wmk_width, $wmk_height) = getimagesize('images/logo.png');
        $x = ($width - $wmk_width) / 2;
        $y = ($height - $wmk_height) / 2;
    
        $wmk = imagecreatefrompng('images/logo.png');
        imagecopymerge($image, $wmk, $x, $y, 0, 0, $wmk_width, $wmk_height, 20);
        imagedestroy($wmk);
    }

//save the image with the filter applied
imagejpeg($image, $dir . '/' . $_POST['id'] . '.jpg', 100);

//set the dimensions for the thumbnail
$thumb_width = $width * 0.10;
$thumb_height = $height * 0.10;

//create the thumbnail
$thumb = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumb_width,
$thumb_height, $width, $height);
imagejpeg($thumb, $dir . '/' . $_POST['id'] . '.jpg', 100);
imagedestroy($thumb);
?>
<html>
 <head>
  <title>Here is your pic!</title>
 </head>
 <body>
  <h1>Your image has been saved!</h1>
  <img src="images/<?php echo $_POST['id']; ?>.jpg" />
 </body>
</html>
<?php
} else {
?>
<html>
 <head>
  <title>Here is your pic!</title>
 </head>
<body
 <h1>So how does it feel to be famous?</h1>
 <p>Here is the picture you just uploaded to our servers:</p>
<?php
  if ($_POST['submit'] == 'Upload') {
	$imagename = 'images/' . $image_id . '.jpg';
}
else {
	$imagename = 'image_effect.php?id=' . $image_id . '&e=' .
		$_POST['effect'];
	if (isset($_POST['emb_caption'])) {
		$imagename .= '&capt=' . urlencode($image_caption);
		}
if (isset($_POST['emb_logo'])) {
$imagename .= '&logo=1';
}
	}
?>
	<img src="<?php echo $imagename; ?>" style="float:left;">
<table>

 <tr><td>Image Saved as: </td><td><?php echo $image_id . '.jpg'; ?></td></tr>
 
 <tr><td>Height: </td><td><?php echo $height; ?></td></tr>
 <tr><td>Width: </td><td><?php echo $width; ?></td></tr>
 <tr><td>Upload Date: </td><td><?php echo $image_date; ?></td></tr>
</table>
<p>You may apply special options to your image below.  Note:  saving an image 
 with any of the filters applied <em>cannot be undone</em>.</p>
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
 <div>
 <input type="hidden" name="id" value="<?php echo $image_id;?>"/>
 Filter: <select name="effect">
 
 <option value="-1">None</option>
 <?php
	echo '<option value="' . IMG_FILTER_GRAYSCALE . '"';
	if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GRAYSCALE) {
		echo ' selected=selected"';
	}
	echo '>Black and White</option>';
	
	echo '<option value="' . IMG_FILTER_GAUSSIAN_BLUR . '"';
	if (isset($_POST['effect']) && $_POST['effect'] == 	IMG_FILTER_GAUSSIAN_BLUR) {
	echo ' selected="selected"';
	}
	echo '>Blur</option>';
	
	echo '<option value="' . IMG_FILTER_EMBOSS . '"';
	if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_EMBOSS) {
		echo ' selected="selected"';
	}
	echo '>Emboss</option>';
	
	echo '<option value="' . IMG_FILTER_NEGATE . '"';
	if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_NEGATE) {
		echo ' selected="selected"';
	}
		echo '>Negative</option>';
	?>
		</select>
		<br/><br/>
	<?php
		echo '<input type="checkbox" name="emb_caption"';
		if (isset($_POST['emb_caption'])) {
			echo ' checked="checked"';
		}
		echo '>Embed caption in image?';
		echo '<br/> <br/><input type="checkbox" name="emb_logo"';
if (isset($_POST['emb_logo'])) {
echo ' checked="checked"';
}
echo ' > Embed watermarked logo in image?';
	?>
		<br/><br/>
		<input type="submit" value="Preview" name="submit" />
		
		<input type="submit" value="Save" name="submit" />
	   </div>
	  </form>
</body>
</html>
<?php
}
?>
image_upload.html

Code:
<html>
 <head>
  <title>Upload your pic to our site!</title>
  <style type="text/css">
  <!--
 td {vertical-align: top}
	-->
	</style>
   </head>
   <body>
    <form action="check_image.php" method="post" enctype="multipart/form-data">
	 <table>
	  <tr>
	   <td>Your Username</td>
	   <td><input type="text" name="username" /></td>
	   </tr>
	   <td>Upload Image*</td>
	   <td><input type="file" name="uploadfile" /></td>
	   </tr><tr>
	    <td colspan="2">
		<small><em>* Acceptable image formats include: GIF, JPG/JPEG and PNG.
		</em></small>
	   </td>
	  </tr><tr>
	   <td>Image Caption<br/>
	   </td>
	   <td><input type="text" name="caption" /></td>
	   </tr><tr>
	   <td colspan="2" style="text-align: center">
	   <input type="submit" name="submit" value="Upload"/>
	   </td>
	   </tr>
	  </table>
	 </form>
	 </body>
	 </html>
image_effect.php

Code:
<?php
//change this path to match yoru images directory
$dir ='C:/wamp/www/moviesite/images';

putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';
//maek sure the requested image is valid
if (isset($_GET['id']) && ctype_digit($_GET['id']) && file_exists($dir . '/'.
	$_GET['id'] . '.jpg')) {
	$image = imagecreatefromjpeg($dir . '/' . $_GET['id'] . '.jpg');


} else {
	die('invalid image specified');

}
//apply the filter
$effect = (isset($_GET['e'])) ? $_GET['e'] : -1;
switch($effect) {
case IMG_FILTER_NEGATE:
	imagefilter($image, IMG_FILTER_NEGATE);
	break;
case IMG_FILTER_GRAYSCALE:
	imagefilter($image, IMG_FILTER_GRAYSCALE);
	break;
case IMG_FILTER_EMBOSS:
	imagefilter($image, IMG_FILTER_EMBOSS);
	break;
case IMG_FILTER_GAUSSIAN_BLUR:
	imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
	break;
}
//add the caption if requested
if (isset($_GET['capt'])) {
	imagegettftext($image, 12, 0, 20, 20, 0, $font, $_GET['capt']);
}
//add the logo watermark if requested
if (isset($_GET['logo'])) {
// determine x and y position to center watermark
list($width, $height) = getimagesize($dir . '/' . $_GET['id'] . '.jpg');
list($wmk_width, $wmk_height) = getimagesize('images/logo.png');
$x = ($width - $wmk_width) / 2;
$y = ($height - $wmk_height) / 2;
$wmk = imagecreatefrompng('images/logo.png');
imagecopymerge($image, $wmk, $x, $y, 0, 0, $wmk_width, $wmk_height, 20);
imagedestroy($wmk);
}
//show the image
header('Content-Type: image/jpeg');
imagejpeg($image, '', 100);
?>

gallery.php

Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or
	die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die (mysql_error($db));

//change this path to match your images directory
$dir ='images';

//change this path to match your thumbnail directory
$thumbdir = $dir . '/thumbs';

//change this path to match your fonts directory and the desired font
putenv('GDFONTPATH=' . 'C:/Windows/Fonts/');
$font = getenv('GDFONTPATH') . 'arial.ttf';
?>
<html>
 <head>
 <title>Welcome to our Photo Gallery</title>
 <style type="text/css">
 th { background-color:  #999; }
 .odd_row { background-color: #EEE; }
 .even_row { background-color: #FFF; }
</style>
</head>
<body>
<p>Click on any image to see it full sized.</p>
<table style="width:100%;">
<tr>
 <th>Image</th>
 <th>Caption</th>
 <th>Uploaded By</th>
 <th>Date Uploaded</th>
</tr>
<?php
//get the thumbs
$result = mysql_query('SELECT * FROM images') or die(mysql_error());

$odd = true;
while ($rows = mysql_fetch_array($result)) {
	echo ($odd == true) ? '<tr class="odd_row">' : '<tr class="even_row">';
	$odd = !$odd;
	extract($rows);
	echo '<td><a href="' . $dir . '/' . $image_id . '.jpg">';
	echo '<img src="' . $thumbdir . '/' . $image_id . '.jpg">';
echo '</a></td>';
echo '<td>' . $image_caption . '</td>';
	echo '<td>' . $image_username . '</td>';
	echo '<td>' . $image_date . '</td>';
	echo '</tr>';
}
?>
</table>
</body>
</html>
 
Old January 19th, 2013, 10:36 AM
Registered User
 
Join Date: Jan 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default It works!

I hope this files will be helpfull.
This files show caption and watermark preview. They work for me!
Nearly i'll try with gallery.

check_image.php:

Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//change this path to match your images directory
$dir ='C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/images';

//set font (book code dont work for it)
putenv('GDFONTPATH=C:/Windows/Fonts');
$font = getenv('GDFONTPATH') . '/arial.ttf';

///////////////////rest comments will be in spanish

//controlar la imagen cargada
if ($_POST['submit'] == 'Upload') {
//asegurar la transferencia correcta del archivo
    if ($_FILES['uploadfile']['error'] != UPLOAD_ERR_OK) {
        switch ($_FILES['uploadfile']['error']) {
            case UPLOAD_ERR_INI_SIZE:
                die('el archivo subido excede el tamaño máximo de subida según la directiva en php.ini');
                break;
            case UPLOAD_ERR_FORM_SIZE:
                die('el archivo subido excede el tamaño máximo de subida especificado en el formulario');
                break;
            case UPLOAD_ERR_PARTIAL:
                die('el archivo fue subido solo parcialmente');
                break;
            case UPLOAD_ERR_NO_FILE:
                die('no se ha subido ningun archivo');
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                die('el servidor no encuentra el directorio temporal');
                break;
            case UPLOAD_ERR_CANT_WRITE:
                die('el servidor ha fallado guardando el archivo subido');
                break;
            case UPLOAD_ERR_EXTENSION:
                die('carga de imagen detenida por extensión erronea de archivo');
                break;
        }
    }
//obtener la info de la imagen que acaba de cargarse
    $image_caption = $_POST['caption'];
    $image_username = $_POST['username'];
    $image_date = date('Y-m-d');
    list($width, $height, $type, $attr) = getimagesize($_FILES['uploadfile']['tmp_name']);
//asegurar que la imagen es del tipo permitido
    $error = 'la imagen subida no tiene la extensión permitida';
    switch ($type) {
        case IMAGETYPE_GIF:
            $image = imagecreatefromgif($_FILES['uploadfile']['tmp_name']) or die('$error');
            break;
        case IMAGETYPE_JPEG:
            $image = imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']) or die('$error');
            break;
        case IMAGETYPE_PNG:
            $image = imagecreatefrompng($_FILES['uploadfile']['tmp_name']) or die('$error');
            break;
        default:
            die('$error');
            break;
    }
//guardar info en la tabla imagen
    $query = 'insert into images (image_caption, image_username, image_date)
    values ("' . $image_caption . '","' . $image_username . '","' . $image_date . '")';
    $result = mysql_query($query, $conectar) or die(mysql_error($conectar));
//el nuevo registro
    $last_id = mysql_insert_id();
//aprovechando el id (identificador unívoco) para nombrar la imagen. Así aseguramos no sobreescribir ninguna.
    $image_id = $last_id;
    //guardar la imagen
    imagejpeg($image, $dir . '/' . $image_id . '.jpg');
    imagedestroy($image);
} else {
    //recuperar info de la imagem
    $query = 'select image_id, image_caption, image_username, image_date from images where image_id =' . $_POST['id'];
    $result = mysql_query($query, $conectar) or die(mysql_error($conectar));
    extract(mysql_fetch_assoc($result));
    list($width, $height, $type, $attr) = getimagesize($dir . '/' . $_POST['id'] . '.jpg');
}
if ($_POST['submit'] == 'Save') {
    //asegurarse de que la imagen solicitada es válida
    if (isset($_POST['id']) && ctype_digit($_POST['id']) && file_exists($dir . '/' . $_POST['id'] . '.jpg')) {
        $image = imagecreatefromjpeg($dir . '/' . $_POST['id'] . '.jpg');
    } else {
        die('imagen especificada no válida');
    }
    //aplicar el filtro
    $effect = (isset($_POST['effect'])) ? $_POST['effect'] : -1;
    switch ($effect) {
        case IMG_FILTER_NEGATE:
            imagefilter($image, IMG_FILTER_NEGATE);
            break;
        case IMG_FILTER_GRAYSCALE:
            imagefilter($image, IMG_FILTER_GRAYSCALE);
            break;
        case IMG_FILTER_EMBOSS:
            imagefilter($image, IMG_FILTER_EMBOSS);
            break;
        case IMG_FILTER_GAUSSIAN_BLUR:
            imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
            break;
    }
    //añadir el título, si se solicita
    if (isset($_POST['emb_caption'])) {
        imagettftext($image, 12, 0, 20, 20, 0, $font, $image_caption);
    }
    //añadir marca de agua si se solicita
    if (isset($_POST['emb_logo'])) {
        //posicionar marca de agua
        list($wmk_width, $wmk_height) = getimagesize('images/logo.png');
        $x = ($width - $wmk_width) / 2;
        $y = ($height - $wmk_height) / 2;
        $wmk = imagecreatefrompng('images/logo.png');
        imagecopymerge($image, $wmk, $x, $y, 0, 0, $wmk_width, $wmk_height, 20);
        imagedestroy($wmk);
    }
    //guardar la imagen con el filtro aplicado
    imagejpeg($image, $dir . '/' . $_POST['id'] . '.jpg', 100);
    ?>
    <html>
        <head>
            <title>Esta es tu imagen!</title>
        </head>
        <body>
            <h1>Tu imagen ha sido guardada!</h1>
            <img src="images/<?php echo $_POST['id']; ?>.jpg"/>
        </body>
    </html>
    <?php
} else {
    ?>
    <html>
        <head>
            <title>Esta es tu imagen!</title>
        </head>
        <body>
            <h1>Que se siente al ser famoso?</h1>
            <p>Esta es la imagen que acabas de guardar en el servidor: </p>
            <?php
            if ($_POST['submit'] == 'Upload') {
                $imagename = 'images/' . $image_id . '.jpg';
            } else {
                $imagename = 'image_effect.php?id=' . $image_id . '&e=' . $_POST['effect'];
                if (isset($_POST['emb_caption'])) {
                    $imagename .= '&capt=' . urlencode($image_caption);
                }
                if (isset($_POST['emb_logo'])) {
                    $imagename .= '&logo=1';
                }
            }
            ?>
            <img src="<?php echo $imagename; ?>" style="float: left;"/>
            <table>
                <tr><td>Imagen guardada como: </td><td><?php echo $image_id . '.jpg'; ?></td></tr>
                <tr><td>Altura: </td><td><?php echo $height; ?></td></tr>
                <tr><td>Ancho: </td><td><?php echo $width; ?></td></tr>
                <tr><td>Fecha de subida: </td><td><?php echo $image_date; ?></td></tr>
            </table>
            <p>Puedes aplicar opciones especiales a tu imagen a continuación.<br/> Nota: si guardas la imagen con 
                alguna de las opciones aplicadas <em>no podrás deshacerlo</em>.</p>
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
                <div>
                    <input type="hidden" name="id" value="<?php echo $image_id; ?>"/>
                    Filter: <select name="effect">
                        <option value="-1">None</option>
                        <?php
                        echo '<option value="' . IMG_FILTER_GRAYSCALE . '"';
                        if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GRAYSCALE) {
                            echo ' selected="selected"';
                        }
                        echo'>Blanco y Negro</option>';
                        echo '<option value="' . IMG_FILTER_GAUSSIAN_BLUR . '"';
                        if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_GAUSSIAN_BLUR) {
                            echo ' selected="selected"';
                        }
                        echo'>Desenfocada</option>';
                        echo '<option value="' . IMG_FILTER_EMBOSS . '"';
                        if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_EMBOSS) {
                            echo ' selected="selected"';
                        }
                        echo'>Relieve</option>';
                        echo '<option value="' . IMG_FILTER_NEGATE . '"';
                        if (isset($_POST['effect']) && $_POST['effect'] == IMG_FILTER_NEGATE) {
                            echo ' selected="selected"';
                        }
                        echo'>Negativo</option>';
                        ?>
                    </select>
                    <br/><br/>
                    <?php
                    echo '<input type="checkbox" name="emb_caption"';
                    if (isset($_POST['emb_caption'])) {
                        echo ' checked="checked"';
                    }
                    echo '/>Añadir título a la imagen?';
                    echo '<br/><br/><input type="checkbox" name="emb_logo"';
                    if (isset($_POST['emb_logo'])) {
                        echo ' checked="checked"';
                    }
                    echo '/>Añadir marca de agua?';
                    ?>
                    <br/><br/>
                    <input type="submit" value="Preview" name="submit"/>
                    <input type="submit" value="Save" name="submit"/>
                </div>
            </form>
        </body>
    </html>
    <?php
}
?>
image_effect.php:
Code:
<?php
//connect to MySQL
$db = mysql_connect('localhost', 'bp6am', 'bp6ampass') or 
    die ('Unable to connect. Check your connection parameters.');
mysql_select_db('moviesite', $db) or die(mysql_error($db));

//change this path to match your images directory
$dir ='C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/images';

//set fuente
putenv('GDFONTPATH=C:/Windows/Fonts');
$font = getenv('GDFONTPATH'). '/arial.ttf';


///////////////////rest comments will be in spanish


//asegurar que la imagen solicitada es válida
if (isset($_GET['id']) && ctype_digit($_GET['id']) && file_exists($dir . '/' . $_GET['id'] . '.jpg')) {
    $image = imagecreatefromjpeg($dir . '/' . $_GET['id'] . '.jpg');
} else {
    die('imagen especificada no válida');
}
//aplicar el filtro
$effect = (isset($_GET['e'])) ? $_GET['e'] : -1;
switch ($effect) {
    case IMG_FILTER_GRAYSCALE:
        imagefilter($image, IMG_FILTER_GRAYSCALE);
        break;
    case IMG_FILTER_EMBOSS:
        imagefilter($image, IMG_FILTER_EMBOSS);
        break;
    case IMG_FILTER_GAUSSIAN_BLUR:
        imagefilter($image, IMG_FILTER_GAUSSIAN_BLUR);
        break;
    case IMG_FILTER_NEGATE:
        imagefilter($image, IMG_FILTER_NEGATE);
        break;
    default:
        break;
}
//añadir el título, si se solicita
if (isset($_GET['capt'])) {
    imagettftext($image, 12, 0, 20, 20, 0, $font, $_GET['capt']);
}
//añadir marca de agua si se solicita
if (isset($_GET['logo'])) {
    list($width, $height) = getimagesize($dir . '/' . $_GET['id'] . '.jpg');
    list($wmk_width, $wmk_height) = getimagesize('images/logo.png');
    $x = ($width - $wmk_width) / 2;
    $y = ($height - $wmk_height) / 2;
    
    $wmk = imagecreatefrompng('images/logo.png');
    imagecopymerge($image, $wmk, $x, $y, 0, 0, $wmk_width, $wmk_height, 20);
    imagedestroy($wmk);
}
//mostrar la imagen
header('Content-Type: image/jpeg');
imagejpeg($image, '', 100);
?>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 1 - Working Widget Code php4ever BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 5 September 5th, 2013 02:16 PM
Working Code for Chapter 4 clomby BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 December 26th, 2005 06:44 AM
Code not working well vinish Beginning PHP 2 November 11th, 2005 08:02 PM
Working / revised set up instructions ? HSCIII BOOK: ASP.NET Website Programming Problem-Design-Solution 0 January 31st, 2004 11:41 PM
code not working Toka1 Javascript How-To 12 December 17th, 2003 05:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.