473,386 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Resize an image stored in a DB prior to diplaying it on page

Hi,

I have a collection of images stored in a DB. They are there for the
purpose of a news system. When the user views the homepage it will
diplay cropped versions of the news where the user will them click the
'read more' link to view the entire article. It will also display a
thumbnail of the article image. As the image is stored at its full
display size in the DB I need to be able to resize it before outputing
it.

To display the image I use a PHP file called 'imageviewer.php' and pass
the unique idetifier as a GET parameter. Once the correct image data
column field has been queried I use the following line to output it
within the <img> tag:
echo pg_unescape_bytea($imgdata); //PostgreSQL database
However, in this instance I need to be able to resize it to a thumbnail
image prior to outputting. How would I do this?

Cheers

Burnsy

Sep 19 '05 #1
6 2508

bi******@yahoo.co.uk wrote:
Hi,

I have a collection of images stored in a DB. They are there for the
purpose of a news system. When the user views the homepage it will
diplay cropped versions of the news where the user will them click the
'read more' link to view the entire article. It will also display a
thumbnail of the article image. As the image is stored at its full
display size in the DB I need to be able to resize it before outputing
it.

To display the image I use a PHP file called 'imageviewer.php' and pass
the unique idetifier as a GET parameter. Once the correct image data
column field has been queried I use the following line to output it
within the <img> tag:
echo pg_unescape_bytea($imgdata); //PostgreSQL database
However, in this instance I need to be able to resize it to a thumbnail
image prior to outputting. How would I do this?

Cheers

Burnsy


Ok, not many replies. Can anybody tell me how this might be done with
an image stored in a MySQL db if possible? Cheers

Burnsy

Sep 21 '05 #2
echo pg_unescape_bytea($imgdata); //PostgreSQL database However, in this instance I need to be able to resize it to a thumbnail
image prior to outputting. How would I do this?

First <http://www.php.net/manual/en/function.imagecreatefromstring.php>
then <http://www.php.net/manual/en/function.imagecopyresized.php> or
<http://www.php.net/manual/en/function.imagecopyresampled.php>, then
<http://www.php.net/manual/en/function.imagejpeg.php>, and finally
<http://www.php.net/manual/en/function.imagedestroy.php>.

---
Steve

Sep 21 '05 #3
NC
bi******@yahoo.co.uk wrote:

I need to be able to resize it to a thumbnail image
prior to outputting. How would I do this?


The easy answer is that you probably shouldn't do it at all.
Image resizing is a CPU-intensive process, so resizing should
be done once, when uploading the image to the server. The
resulting thumbnail would then be stored next to the full-size
image.

Also, the wisdom of storing images in databases is questionable.
If you have a PHP page with five images on it, every time someone
views it, six simultaneous connections to the database will be
opened.

For details on resizing, see documentation for imagecopyresized()
and imagecopyresampled() functions:

http://www.php.net/imagecopyresized
http://www.php.net/imagecopyresampled

Cheers,
NC

Sep 21 '05 #4
Steve wrote:
echo pg_unescape_bytea($imgdata); //PostgreSQL database

However, in this instance I need to be able to resize it to a
thumbnail image prior to outputting. How would I do this?

First
<http://www.php.net/manual/en/function.imagecreatefromstring.php>
then <http://www.php.net/manual/en/function.imagecopyresized.php> or
<http://www.php.net/manual/en/function.imagecopyresampled.php>, then
<http://www.php.net/manual/en/function.imagejpeg.php>, and finally
<http://www.php.net/manual/en/function.imagedestroy.php>.

Some implementations won't have the JPEG support compiled in. There's
sometimes a program on UNIX systems called convert that can do what's
needed.

http://www.die.net/doc/linux/man/man1/convert.1.html

Brian
Sep 21 '05 #5
hi every body
while i see alot of image functions in php but really i ever use one,

bissa...@yahoo.co.uk

i may adivse you to store 2 things :

1- the path in the DB of the small and big images you may need one
field the (image_path) and the add the big images path programatically.

2- you need also to store the image or you may need to create your own
uploade system to uploade the images (big and small), so you need to
upload the image twice the (small & big).

if you store the image in the DB in binary format i think it take a
time to be load and if it is more than 100KB it may reduce the
execution of your web page.

check it

Sep 22 '05 #6
A) You probably wouldn't want to store the image in th DB in the first
place
B) Since you've done that, save the image in the /tmp/ forlder after
reading it from the DB, resize that image and display it on the page.
C) If you plan on having lots of visualizations of the thumbnail,
you'll most probably want to save the image for future use... do this
by either :
1 - updating the DB with a pointer to the resized image
2 - Check if the file name of the thumbnail exists in a give Directory
before processing the image.

Preferably, you'd want to store a pointer in the DB of both the Thumb
and the main image.This way, you transfer less data between PHP and
MySQL, hence making your code quicker to execute.

Sep 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Charles Packer | last post by:
From one of the online Javascript tutorials, I learned how to open a new window and set its size. I'm building a page that has several small photographs, and I want to let the viewer examine...
1
by: John Scott | last post by:
I am storing an image in an SQL database and have one field as an image datatype. I am also using a webservice to transport data. I want to be able to resize the image and pass back a thumbnail...
2
by: rams.kakara | last post by:
hi, My page have background image,on that image have more images and text. My problem is whenever resize browser that images are not resized and also not moved correct place .(i.e look not like...
9
by: Don | last post by:
Does anyone know where I can find a client-side function I can reference from within an HTML/JavaScript web page? I'm currently using a core PHP function to do this, but I'd rather do it on the...
2
by: Robson Carvalho Machado | last post by:
Dear Friends, Does anybody knows how to use the below code with an image stored at SQL Image field? Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
14
by: Rudy | last post by:
Hello all! I been trying to get a handle with Images. I have learned alot from the fine people here. So, I also learned that thumbnail images look terrible taken from a digital cam. I know why...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
22
by: simon2x1 | last post by:
i have an image which width is 213 and height is 200 when i echo the image and i resize it echo "<img src='company/$present' width='70' height='68'/>"; the image was not as clear as when it was...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.