Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 May 16th, 2005, 11:35 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Image from record

WE hi to all small problem i think:D


how i can pass to a function imagecreatejpeg ( ); the valour of a record taken from a db????
i try to explain better:
i take the valour of a record and i put to a variabile es:
$myimage=$myquery['image'];//this will be the name of the image
can i write...
imagecreatejpeg ($myimage);


 
Old May 17th, 2005, 12:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

>> can i write...
>> imagecreatejpeg ($myimage);

Yes.
http://www.mediasworks.com/scripts/
 
Old May 17th, 2005, 02:06 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great.... thanks anshul:D

 
Old May 17th, 2005, 05:35 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Litle problem crashes:D
as i told up, i've taken, the name of the image from a record.
So hang-on one moment, i try to explay whath i'm try to do.

I've got a dinamic menu i've my table in the DB called menu with id_menu, title_menu, description_menu, and image_menu this records are fill-up with info from a form that i've done, the title the description and the name of the file image that i upload to a fold in root site.

now i've done my query that extract all my record into a while that cicle and show all of my record this is my code.
Logicaly i upload a great image thougth the form and i want the thumb.

this is my code:....

Code:
<?php require_once('Connections/feeling.php'); ?>
<?php
mysql_select_db($database_feeling, $feeling);
$query_visual = "SELECT * FROM menu_visual_sezioni ORDER BY rank asc";
$visual = mysql_query($query_visual, $feeling) or die(mysql_error());
$row_visual = mysql_fetch_assoc($visual);
$totalRows_visual = mysql_num_rows($visual);
?>
<html><head></head><body>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>
      <?php do { ?>
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>
          <table width="100%"  border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="testo-di-navigazione">--<?php echo $row_visual['nome_menu_v_sezione']; ?></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <td><?php echo $row_visual['descrizione']; ?></td>
              </tr>
          </table></td>
          <td class="td-150px"><a href="<?php $row_visual['link']?>"><?php 
          $mydir = "uploaded_image_visual";
          $mynameimage = $row_visual['prewiew_image']; 
          $myimage = $mydir."/".$mynameimage ;
          //echo $myimage."";
          $mainimage = imagecreatefromjpeg($myimage);
          $mainWidth = imagesx($mainimage);
          $mainHeight = imagesy($mainimage);
          $thumbHeight = intval($mainHeight / 4);
          $thumbWidth = intval($mainWidth / 4);
          $myThumb = imagecreatetruecolor ( $thumbWidth, $thumbHeight);
          imagecopyresampled ($myThumb,$mainimage,0,0,0,0,$thumbWidth,$thumbHeight,$mainWidth,$mainHeight);
          //header("Content-type:image/jpeg");
          imagejpeg($myThumb);
          imagedestroy($myThumb);
          imagedestroy($mainimage);
          echo imagejpeg($myThumb).'width="150" height="110" border="0" />';

          ?></a></td>
        </tr>
        <tr class="tr-sfondo-puntini">
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
      <?php } while ($row_visual = mysql_fetch_assoc($visual)); ?></td>
  </tr>
</table>
</body></html>
<?php
mysql_free_result($visual);
?>

Where the fault? some one can explay best practise to implement the thumb???

 
Old May 17th, 2005, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

>> while ($row_visual = mysql_fetch_assoc($visual));
See if this helps, while ($row_visual == mysql_fetch_assoc($visual));

 
Old May 17th, 2005, 08:06 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi anshul, great thank you for your super speed in replay me

my problem is not on the query, is on the part of the script that involves the image

Code:
<td><?php echo $row_visual['descrizione']; ?></td>
              </tr>
          </table></td>
          <td class="td-150px"><a href="<?php $row_visual['link']?>"><?php 
          $mydir = "uploaded_image_visual";
          $mynameimage = $row_visual['prewiew_image']; 
          $myimage = $mydir."/".$mynameimage ;
          //echo $myimage."";
          $mainimage = imagecreatefromjpeg($myimage);
          $mainWidth = imagesx($mainimage);
          $mainHeight = imagesy($mainimage);
          $thumbHeight = intval($mainHeight / 4);
          $thumbWidth = intval($mainWidth / 4);
          $myThumb = imagecreatetruecolor ( $thumbWidth, $thumbHeight);
          imagecopyresampled ($myThumb,$mainimage,0,0,0,0,$thumbWidth,$thumbHeight,$mainWidth,$mainHeight);
          //header("Content-type:image/jpeg");
          imagejpeg($myThumb);
          imagedestroy($myThumb);
          imagedestroy($mainimage);
          echo imagejpeg($myThumb).'width="150" height="110" border="0" />';

          ?></a></td>
i've wrote all the code for let you understand better, but it must be there the wrong code....

 
Old May 18th, 2005, 01:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

Code:
<a href="<?php $row_visual['link']?>">
Is it <a href="<?php echo $row_visual['link']; ?>">
You've used many functions in your script, there may be error in number of arguments passed or function definition, if you've written that functions. PHP is surely showing the line numbers where errors occured. Use an editor like Notepad++ or HomeSite to know which line/piece-of-code has the error.

 
Old May 18th, 2005, 08:24 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mmm....
so start from the bone...
I've got this code:
Code:
<?php
//this is my image
        $mydir = "uploaded_image_visual";
    $mynameimage = "sezioni_capelli.jpg"; 
    $myimage = $mydir."/".$mynameimage ;
//start work with    
     $mainImage = imagecreatefromjpeg($myimage);   
     $mainWidth = imagesx($mainImage);
     $mainHeight = imagesy($mainImage);
     $thumbWidth = intval($mainWidth / 4);
     $thumbHeight = intval($mainHeight / 4);
$myThumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($myThumbnail, $mainImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
header("Content-type: image/jpeg");
imagejpeg($myThumbnail);
imagedestroy($myThumbnail);
imagedestroy($mainImage);
//finish to work whith the image

//echo'<html><head></head><body>'.imagejpeg($myThumbnail).'</body></html>';
?>
if I use this script as is, no problem i see thumb of the image....perfect.
What about, to have an html output together???
so if i try to do something very simple like this:
Code:
<html>
    <head>
    </head>
<body>
    <table width="100%"  border="1" cellspacing="0" cellpadding="0">
        <tr>
            <td>
<?php
        $mydir = "uploaded_image_visual";
        $mynameimage = "sezioni_capelli.jpg"; 
        $myimage = $mydir."/".$mynameimage ;

     $mainImage = imagecreatefromjpeg($myimage);   
     $mainWidth = imagesx($mainImage);
     $mainHeight = imagesy($mainImage);
     $thumbWidth = intval($mainWidth / 4);
     $thumbHeight = intval($mainHeight / 4);
$myThumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($myThumbnail, $mainImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
header("Content-type: image/jpeg");
imagejpeg($myThumbnail);
imagedestroy($myThumbnail);
imagedestroy($mainImage);

?>
</td>
</tr>
</table>
</body>
</html>
I take an error that say: The image "http://localhost/myfile.php" can't be visualized becouse it contais some errors......

How do you do to show a resized image and html together???

 
Old May 19th, 2005, 02:02 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anshul
Default

<?php
function image_generator() {
    $mydir = "uploaded_image_visual";
    $mynameimage = "sezioni_capelli.jpg";
    $myimage = $mydir."/".$mynameimage ;
    $mainImage = imagecreatefromjpeg($myimage);
    $mainWidth = imagesx($mainImage);
    $mainHeight = imagesy($mainImage);
    $thumbWidth = intval($mainWidth / 4);
    $thumbHeight = intval($mainHeight / 4);
    $myThumbnail = imagecreatetruecolor($thumbWidth, $thumbHeight);
    imagecopyresampled($myThumbnail, $mainImage, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
    header("Content-type: image/jpeg");
    $harvest=imagejpeg($myThumbnail);
    imagedestroy($myThumbnail);
    imagedestroy($mainImage);
    return $harvest;
}
?>

<table><tr><td><?php echo image_generator(); ?></td></tr></table>

 
Old May 19th, 2005, 11:27 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

oh cool thanks all in a function....:D






Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a record row, not just the record. Coby Access VBA 1 April 30th, 2007 06:29 AM
how to add new record as first record in dataset [email protected] ASP.NET 1.0 and 1.1 Professional 4 April 21st, 2006 05:23 AM
Record locking - user needs the next queued record cbtoolkit SQL Server 2000 0 December 6th, 2004 08:29 AM
Empty record field, No image dstubblefield Dreamweaver (all versions) 6 September 3rd, 2004 01:05 AM
Sub record not associating with Main record Ron V Access 1 August 31st, 2004 09:21 AM





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