Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 27th, 2010, 08:38 AM
Registered User
 
Join Date: Jan 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chp 7 Caption & Watermark p202

I can't get the Caption & Watermark to work on page 202 onwards?!

I have downloaded the original code...changed the paths to my htdocs. But this still doesn't work....everything else but this.

Help.
Reply With Quote
  #2 (permalink)  
Old February 13th, 2010, 01:43 AM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Location: Wolfeboro, New Hampshire / Boston
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
Default Solution for caption

I haven't gotten to the watermark section yet, but was having the same problem with the caption. The solution I found was to replace the 2 lines of code at the beginning of both files with this:

Code:
putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';
This solved the problem, at least on Windows Vista.

HTH,
Boz
Reply With Quote
  #3 (permalink)  
Old March 3rd, 2010, 12:01 PM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy

Quote:
Originally Posted by BozHogan View Post
I haven't gotten to the watermark section yet, but was having the same problem with the caption. The solution I found was to replace the 2 lines of code at the beginning of both files with this:

Code:
putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';
This solved the problem, at least on Windows Vista.

HTH,
Boz
After this replaced lines i have the same problem... The code does'nt work!
Can you Help me?
Reply With Quote
  #4 (permalink)  
Old March 3rd, 2010, 01:03 PM
Authorized User
Points: 105, Level: 2
Points: 105, Level: 2 Points: 105, Level: 2 Points: 105, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2010
Location: Wolfeboro, New Hampshire / Boston
Posts: 25
Thanks: 1
Thanked 4 Times in 4 Posts
Default

I'm happy to give it a try. Could you post your code? Or is it the downloaded code that you're using? Also, could you be more specific about it not working? What is it doing? Any error message in the browser or in the error log?

Boz
Reply With Quote
  #5 (permalink)  
Old March 4th, 2010, 06:21 AM
Authorized User
 
Join Date: Dec 2009
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
Unhappy

Hello, thank you for your attention, but my code is similar to downloaded code! my problem is that i don't see change in Caption & Watermark! In case of caption i see only a rectangular form without image and in case of watermark i see the same image without merge of two photo images!
My check_image.php file is:
Code:
<?php
// connessione a 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));

// cambiare questo percorso in modo che corrisponda a quello della cartella
// images in uso
$dir ='C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/images';

// modificare questo percorso in modo che coincida con la cartella per le
// miniature in uso
$thumbdir = $dir . '/thumbs';

// modificare questo percorso in modo che coincida con la cartella Font del
// computer in uso e definire il font desiderato
putenv('GDFONTPATH=' . 'C:/Windows/Fonts');
$font = getenv('GDFONTPATH') . 'arial.ttf';

// gestisce l'immagine caricata
if ($_POST['submit'] == 'Upload') {

// si assicura che il caricamento sia avvenuto correttamente
    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 directive 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 server is missing a temporary folder.');
            break;
        case UPLOAD_ERR_CANT_WRITE:
            die('The server failed to write the uploaded file to disk.');
            break;
        case UPLOAD_ERR_EXTENSION:
            die('File upload stopped by extension.');
            break;
        }
    }

    // recupera le informazioni sull'immagine appena caricata
    $image_caption = $_POST['caption'];
    $image_username = $_POST['username'];
    $image_date = date('Y-m-d');
    list($width, $height, $type, $attr) =
        getimagesize($_FILES['uploadfile']['tmp_name']);

    // si assicura che il file caricato sia effettivamente un tipo di immagine supportato
    $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);
         break;
    default:
         die($error);
    }

    // inserisce nella tabella images le informazioni
    $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));

    // recupera il valore image_id che MySQL ha generato automaticamente quando
    // abbiamo inserito le informazioni sull'immagine nella tabella
    // il nuovo record
    $last_id = mysql_insert_id();
    $image_id = $last_id;
    imagejpeg($image, $dir . '/' . $image_id . '.jpg');
    imagedestroy($image);
 } else {
 // recupera le informazioni sull'immagine
     $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') {
     // si assicura che l'immagine richiesta sia valida
         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');
         }

     // applica il 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;
        }

     // aggiunge la didascalia, se richiesta
        if (isset($_POST['emb_caption'])) {
            imagettftext($image, 12, 0, 20, 20, 0, $fntdir . '/' . 'arial.ttf', $image_caption);
        }
     // aggiunge il logo watermark, se richiesto
         if (isset($_POST['emb_logo'])) {
     // determina la posizione x e y per centrare il 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);
         }

     // salva l'immagine col filtro applicato
        imagejpeg($image, $dir . '/' . $_POST['id'] . '.jpg', 100);
     
     // imposta le dimensioni delle miniature
        $thumb_width = $width * 0.10;
        $thumb_height = $height * 0.10;
        
     // crea la miniatura
        $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 options 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
   }
  ?>
My image_effect.php file is:
Code:
<?php
// cambiare questo percorso in modo che corrisponda a quello della cartella
// images in uso
$dir ='C:/Programmi/Apache Software Foundation/Apache2.2/htdocs/images';

// modificare questo percorso in modo che coincida con la cartella Font del
// computer in uso e definire il font desiderato
putenv('GDFONTPATH=' . 'C:/Windows/Fonts');
$font = getenv('GDFONTPATH') . 'arial.ttf';

// si assicura che l'immagine richiesta sia valida
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');
}

// applica il filtro
$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;
}

// aggiunge la didascalia, se richiesta
   if (isset($_GET['capt'])) {
   imagettftext($image, 12, 0, 20, 20, 0, $font, $_GET['capt']);
   }
// aggiunge il logo watermark, se richiesto
if (isset($_GET['logo'])) {
// determina la posizione x e y per centrare il watermark
   list($width, $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);
}

// mostra l'immagine
header('Content-Type: image/jpeg');
imagejpeg($image, '', 100);
?>
and my gallery.php file is :

Code:
<?php
// si connette a 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));

// cambiare questo percorso in modo che corrisponda a quello della cartella
// images in uso
$dir = 'images';

// modificare questo percorso in modo che coincida con la cartella per le 
// miniature in uso
$thumbdir = $dir . '/thumbs';
?>
<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
// recupera la miniatura
$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>
Where is the problem? How can i resolve it?
Thanks

Last edited by rickymartini76@yahoo.it; March 5th, 2010 at 11:07 AM..
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Watermark image amirmunir Crystal Reports 0 June 1st, 2006 12:09 PM
Chp 12, common_db.inc & userviewer.php reques jaymax BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 February 1st, 2006 05:18 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
Insert text as watermark in the report? pallavijyo BOOK: Professional Crystal Reports for VS.NET 0 December 15th, 2004 10:14 AM
caption jlnashrod Access VBA 2 April 5th, 2004 10:48 PM



All times are GMT -4. The time now is 11:45 PM.


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