in brief:
Can I perform operations like imagesx() or getimagesize() on raw image
data as retrieved into a variable from a database, without first
saving it as a file? If so, how? If not, what is the best way to
create a temporary file such that it is unlikely to conflict with
other sessions that are performing the same actions?
in more detail:
I have a database that stores an image in a BLOB field, and I want to
display that image on my page either 'as is' or as a thumbnail created
on the fly to a width passed to the <img...> tag by means of a $_GET
variable - so either
<img src="getimage.p hp?imageid=0123 />
in the first instance, or
<img src="getimage.p hp?imageid=0123 &action=thumb&w idth=200 />
in the second.
I'm getting the image from the database like this:
$photoFetchSour ce = $_GET["imageid"];
$photoFetchQuer y = "SELECT * FROM mytable WHERE
photoid=".$phot oFetchSource;
$photoFetchResu lt = mysql_query($ph otoFetchQuery) or die("blah...");
$photoFetchArra y = mysql_fetch_ass oc($photoFetchR esult;
$photo = $photoFetchArra y["photo"];
and I can send the unchanged photo to the page by
header ("Content-type: image/jpg");
echo $photo;
So far, so good...
Unfortunately, I can't do things like
list($width, $height, $type, $attr) =
getimagesize($p hoto)
because '$photo' isn't a file.
I'd like to avoid any unnecessary file operations if I can. Any
suggestions?
--
Charlie 5 2477
Not sure if this will work.
Put
//Do the get blob stuff
header ("Content-type: image/jpg");
echo $photo;
In a separate page called something like image.php. You should pass id
values to the page to display different images, so lets say the image
is id value 1, e.g. image.php?id=1.
Then try:
list($width, $height, $type, $attr) = getimagesize('i mage.php?id=1') ;
A better way to do it is not store the images in the database at all,
but store references to the images, and keep the image files on the
file system. By the simple fact you are storing images in the database
you are creating for yourself lots of unnecessary problems.
On 23 Dec 2005 11:55:47 -0800, in
<11************ **********@g47g 2000cwa.googleg roups.com>
(comp.lang.php) "Chung Leong" <ch***********@ hotmail.com> wrote: Use the VariableStream class given as an example here:
http://fi.php.net/manual/en/function...r-register.php
Thanks, to you and Sean, for your ideas - I'll try them both out: the
more strings to my bow the better! :)
As it happens, shortly after posting, I found the tool that I needed
for the script I had already built: imagecreatefrom string();
Following on from the example in my first post, now I can do
$im = imagecreatefrom string($photo);
which lets me
$photoWidth = imagesx($im);
$photoHeight = imagesy($im);
list($width, $height, $type, $attr) =getimagesize($ im);
etc.,
Although Sean's point about using the filesystem to store images, and
the database to reference them, seems like a good one given the 2048k
limit I have on LONGBOOLs in MySQL...
Cheers all
--
Charlie
Charlie King wrote: Can I perform operations like imagesx() or getimagesize() on raw image data as retrieved into a variable from a database, without first saving it as a file? If so, how?
You can use getimagesize() only on image files. You can, however, use
imagesx() and imagesy() on any image. What you need to do is to pull
data from the database, create an image using imagecreatefrom string()
and feed the resulting image resource to imagesx() and imagesy().
I'm getting the image from the database like this: $photoFetchSour ce = $_GET["imageid"]; $photoFetchQuer y = "SELECT * FROM mytable WHERE photoid=".$phot oFetchSource; $photoFetchResu lt = mysql_query($ph otoFetchQuery) or die("blah..."); $photoFetchArra y = mysql_fetch_ass oc($photoFetchR esult; $photo = $photoFetchArra y["photo"];
and I can send the unchanged photo to the page by
header ("Content-type: image/jpg"); echo $photo;
So far, so good...
Unfortunately, I can't do things like list($width, $height, $type, $attr) = getimagesize($p hoto) because '$photo' isn't a file.
I'd like to avoid any unnecessary file operations if I can. Any suggestions?
Two. First, you can do this:
$img = imagecreatefrom string($photo);
$x = imagesx($img);
$y = imagesy($img);
header ("Content-type: image/jpg");
echo $photo; // or imagejpeg($img) ;
Second, if you store images in a database, you may consider storing
image attributes (width, height, and type) in the database as well and
not worry about obtaining them at execution.
Cheers,
NC
On 23 Dec 2005 14:08:16 -0800, in
<11************ **********@g43g 2000cwa.googleg roups.com>
(comp.lang.php) "NC" <nc@iname.com > wrote: Charlie King wrote: Can I perform operations like imagesx() or getimagesize() on raw image data as retrieved into a variable from a database, without first saving it as a file? If so, how? You can use getimagesize() only on image files. You can, however, use imagesx() and imagesy() on any image. What you need to do is to pull data from the database, create an image using imagecreatefrom string() and feed the resulting image resource to imagesx() and imagesy().
Thanks for that - as it turns out, that's exactly where I ended up :) I'd like to avoid any unnecessary file operations if I can. Any suggestions?
Two. First, you can do this:
$img = imagecreatefrom string($photo); $x = imagesx($img); $y = imagesy($img); header ("Content-type: image/jpg"); echo $photo; // or imagejpeg($img) ;
Spookily similar to the code I have here! lol
Second, if you store images in a database, you may consider storing image attributes (width, height, and type) in the database as well and not worry about obtaining them at execution.
I'd considered that, but there are two issues - a) those dimensions
have to be calculated at some time, and it's as well to do so on the
way out as the way in (although, arguably they'll be extracted more
frequently than they're input...), and b) there is a possibility that
my customer will end up squirting data into the database from
somewhere other than my web front end, and I'd rather be in control
than their supplying good data.
Cheers, NC
Thanks :)
--
Charlie This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kenneth McDonald |
last post by:
Warning: this post may display my utter ignorance of image file format
facts.
As part of a photo album program I'm working on, I'd like to be able
to work with the metadata in JPEG files, which I understand are
really JFIF files holding jpg data. Do any Python modules permit
me to do this? I looked at PIL, but it seemed to operatre at a
higher level, i.e. hiding the file-level implementation details.
At the least I'd like to be able...
|
by: Jason |
last post by:
For some reason, most but not all reports printing from an access
application our client is using will not print any images on the reports
or forms. One report will print the image and data correctly oddly enough.
The image header is embedded using the Insert Image feature and not
loaded into a database. I can move the image to anywhere in the report
and still it will not print out. I've loaded the most recent printer
drivers and...
|
by: John Smith |
last post by:
I know that uploading an image to a database has been covered, oh, about 3
trillion times. However, I haven't found anything covering uploading to a
MySQL database with .net. Please don't recommend storing the image to the
filesystem and only keeping a pointer to that in the table. I want to dump
the image to a table. My code dumps the data into the table, however, I get
the following error when trying to view the image "the image ......
|
by: Josema |
last post by:
Hi,
I have in a database models of cars,
CarID int
CarName varchar
CarFeatures varchar
CarImage binary
I have a class Car that have the properties:
|
by: Sharon |
last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at
http://www.codeproject.com/bitmap/graphicsuite.asp).
I also wrote a small console application in C++ (unmanaged) that uses the
DLL above.
Now the application, together with the above DLL’s is successfully loading a
TIF image file (62992 x 113386 Pixels, Huffman RLE compression, 3200 x 3200
DPI resolution, binary colored (1 Bit Per Pixel), file on disk size 43.08...
| |
by: Tim::.. |
last post by:
Please, please, please help!!!
I have a datagrid that displays a list of contacts on our intranet site
using the ActiveDirectory as it's main Data Source.
I want to be able to show an image of each employee using a popup layer but
am not sure how I match the Active Directory Data to the correct image stored
in an SQL database. I plan on using the users fullname or email address as an
identifier to match up the image with the correct...
|
by: Dean Slindee |
last post by:
Does anybody have an actual example of retrieving an Image data type column
from a SQL Server table using a dataset (not a datareader)? I would like
to see the statements that would move the Image returned in the dataset to a
picture box, like:
For Each dr in ds.tables(0).rows
Pic.Image = dr("ImageColumnName") 'not this simple!
Next
Thanks,
|
by: numbnutz |
last post by:
Hi,
I am currently working on an XML Gallery for my girlfriend's brother who is a photographer. I have created a flash front end template and am using an XML database to load the images and accompanying captions.
The gallery has more than one image and the user can navigate the gallery by clicking forward and backward buttons to take then through the images:
var galleryXML = new XML();
galleryXML.ignoreWhite = true;...
|
by: Johnny Jörgensen |
last post by:
Does anybody know how you can extract an image fron a webpage loaded into a
webbrowser control and either save it to file OR save it in a database?
Cheers,
Johnny J.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |