note 36309 added to function.imagecreatefromstring
| From: | webmaster at siaags dot com | Date: | Sat, 04 Oct 2003 14:37:31 +0000 |
| Subject: | note 36309 added to function.imagecreatefromstring | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-57810@lists.php.net to get a copy of this message | ||
Some say that BLOBS are unefficient or even stupid to use, but the truth is that dinamic content
works much better while having the capability of reading information "attached" in some
way to the image.
imagecreatefromstring gives you the posibility to create great thumbnails, see the examples given in
the comments above.
If you must create an image in the middle of a sea of html, it's always possible using the
output buffering options (see function "ob_start();"), so you don´t have to deal with
annoying "headers already sent..." problems. Some still say that it is not possible, well,
they have to read a little.
If you still cannot get rid of "ÿØÿà", try using your script for creating thumbnails
in a separate file, just call it from your main page, here´s an example:
MY MAIN PAGE CALLS THE THUMBNAILING SCRIPT IN ORDER TO OUTPUT AN IMAGE TO THE BROWSER:
<?php
echo "<img
src=\"view.php?se={$row_Recordset1['id']}\";></img>";
?>
MY THUMBNAILING SCRIPT WORKS IN A SEPARATE FILE "view.php" wich resizes and gives output:
//validate connection
<?php require_once('Connections/promo.php'); ?>
//get "se" variable passed by my MAIN PAGE
<?php
$colname_Recordset1 = "1";
if (isset($HTTP_GET_VARS['se'])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['se'] :
addslashes($HTTP_GET_VARS['se']);
}
mysql_select_db($database_promo, $promo);
//select info from DBASE, creatign logic to get the rigth info
$query_Recordset1 = sprintf("SELECT * FROM files WHERE id = %s", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $promo) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
//Tell browser kind of image to expect
header('Content-Type: image/jpeg');
$data = $row_Recordset1["fileContents"];
//set new height
$size = 115; // new image height script adapted by Raul Rodriguez Haro for mueblesexcell.com.mx
$src = imagecreatefromstring ($data);
$width = imagesx($src);
$height = imagesy($src);
$aspect_ratio = $height/$width;
//start resizing
if ($height <= $size) {
$new_w = $width;
$new_h = $height;
} else {
$new_h = $size;
$new_w = abs($new_h / $aspect_ratio);
}
$img = imagecreatetruecolor ($new_w,$new_h);
//output image
imagecopyresampled ($img,$src,0,0,0,0,$new_w,$new_h,$width,$height);
// determine image type and send it to the brow
imagejpeg($img, '', 90);
imagedestroy($img);
mysql_free_result($Recordset1);
?>
READY!!!!!
You have a fully functional thumbnails gallery.
----
Manual Page -- http://www.php.net/manual/en/function.imagecreatefromstring.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+36309
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+36309&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+36309&report=yes
Search Tool -- http://master.php.net/manage/user-notes.php