Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 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 May 16th, 2005, 11:35 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
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);


Reply With Quote
  #2 (permalink)  
Old May 17th, 2005, 12:58 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
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/
Reply With Quote
  #3 (permalink)  
Old May 17th, 2005, 02:06 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Great.... thanks anshul:D

Reply With Quote
  #4 (permalink)  
Old May 17th, 2005, 05:35 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
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???

Reply With Quote
  #5 (permalink)  
Old May 17th, 2005, 07:31 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
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));

Reply With Quote
  #6 (permalink)  
Old May 17th, 2005, 08:06 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
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....

Reply With Quote
  #7 (permalink)  
Old May 18th, 2005, 01:14 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
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.

Reply With Quote
  #8 (permalink)  
Old May 18th, 2005, 08:24 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
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???

Reply With Quote
  #9 (permalink)  
Old May 19th, 2005, 02:02 AM
Friend of Wrox
 
Join Date: Mar 2004
Location: Bhopal, MP, India.
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>

Reply With Quote
  #10 (permalink)  
Old May 19th, 2005, 11:27 AM
cli cli is offline
Authorized User
 
Join Date: May 2005
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

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
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 hunzian78@yahoo.com 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



All times are GMT -4. The time now is 07:16 AM.


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