 |
| 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
|
|
|
|

May 16th, 2005, 11:35 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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);
|
|

May 17th, 2005, 12:58 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
>> can i write...
>> imagecreatejpeg ($myimage);
Yes.
http://www.mediasworks.com/scripts/
|
|

May 17th, 2005, 02:06 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Great.... thanks anshul:D
|
|

May 17th, 2005, 05:35 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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> </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> </td>
<td> </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???
|
|

May 17th, 2005, 07:31 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
>> while ($row_visual = mysql_fetch_assoc($visual));
See if this helps, while ($row_visual == mysql_fetch_assoc($visual));
|
|

May 17th, 2005, 08:06 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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....
|
|

May 18th, 2005, 01:14 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

May 18th, 2005, 08:24 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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???
|
|

May 19th, 2005, 02:02 AM
|
|
Friend of Wrox
|
|
Join Date: Mar 2004
Posts: 357
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<?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>
|
|

May 19th, 2005, 11:27 AM
|
|
Authorized User
|
|
Join Date: May 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
oh cool thanks all in a function....:D
|
|
 |