Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

creating thumbnails

images php coding issues or problems here.

Moderators: macek, egami, gesf

creating thumbnails

Postby spazman » Fri Mar 16, 2012 2:23 am

i have a script which uploads an image to my file system and also saves the name of the image to a mysql database so i can view the image when looking at records in my mysql table, i now need to create a thumbnail for each image while keeping the original, i have seen a few examples online on how to do this if you specifically say what image you want but how can i do it so it does it when i upload an image with my script, help appreciated.
spazman
New php-forum User
New php-forum User
 
Posts: 1
Joined: Fri Mar 16, 2012 2:18 am

Re: creating thumbnails

Postby L33R » Mon Apr 23, 2012 4:14 am

just set the width & height of the img . Then link to the page showing the image in its full size.


Code: Select all
<html>
<head>
   <title>test</title>
<body>
   <a href="image_view.html"><img src="images/50868449.jpg" width="100" height="100"></a>
</body>
   
</head>
</html>



on the other page :

Code: Select all
<html>
<head>
   <title>test</title>
<body>
   <img src="images/50868449.jpg">

</body>
   
</head>
</html>
User avatar
L33R
New php-forum User
New php-forum User
 
Posts: 132
Joined: Fri Dec 30, 2011 4:27 am
Location: Liverpool

Re: creating thumbnails

Postby JordanMRichards » Wed Apr 25, 2012 6:43 am

Hey SM,
I think I may have solved your issue (if I've understood correctly what you were looking for.)

I coded this bit up, it's dynamic too!
Code: Select all
<html>
<head>
</head>
<body>
<?php
//do your query and then set the image to the result of the query you wanted to doing your SQL database
$imageurl=$query_result;  // Set $query_result to the name of the variable you set to the result.
$height = 150;//height per image;
$width = 150; //width per image;

echo "<img src='".$imageurl."' height='".$height."' width='".$width."'></img>";
?>

</body>
</html>


And there you have it :)

Hope it helped!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 Year Old Programmer & Graphic Artist, Confident and Courageous
Image
User avatar
JordanMRichards
New php-forum User
New php-forum User
 
Posts: 84
Joined: Mon Apr 23, 2012 7:43 am

Re: creating thumbnails

Postby egami » Wed Apr 25, 2012 9:08 am

the height and length of the image doesn't make it a thumbnail, it only displays it smaller. The full size image is sent to the browser, thus spending bandwidth and wait-time.

in order to make a real thumbnail, you'll have to investigate php.net/image_create
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: creating thumbnails

Postby JordanMRichards » Wed Apr 25, 2012 11:16 am

egami, ah yes I see your point.

Here's some nice videos explaining how to create a thumbnail. (in order)

http://www.youtube.com/watch?v=sBGpp5-GBdM
http://www.youtube.com/watch?v=e_uD7NCSHfM
http://www.youtube.com/watch?v=cRwziqA6fR4

Hope this helps :)

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 Year Old Programmer & Graphic Artist, Confident and Courageous
Image
User avatar
JordanMRichards
New php-forum User
New php-forum User
 
Posts: 84
Joined: Mon Apr 23, 2012 7:43 am

Re: creating thumbnails

Postby pewe » Fri May 25, 2012 6:08 am

Are your images photographs (jpg) or other types?
pewe
New php-forum User
New php-forum User
 
Posts: 16
Joined: Fri May 25, 2012 6:05 am

Re: creating thumbnails

Postby Nullsig » Fri May 25, 2012 6:55 am

This is all you need for creating thumbs:
http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

The class accommodates png, gif and jpg files. It will allow you to resize based on a required height or width or just by defining how much smaller (or bigger) you want the file.
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Re: creating thumbnails

Postby pewe » Fri May 25, 2012 7:16 am

Really useful post Nullsig. Thanks - I will find that useful.

The reason I asked about photographs is that (as I understand it) when most cameras take a pictures and the RAW image is converted in the camera to a jpg, most internal camera software systems create and store a thumbnail in the jpg.

This thumbnail can be extracted from the jpg and displayed as a link to the full size image using PHP.

I have a small 'gallery' script that does this - although I don't understand the coding :oops:
pewe
New php-forum User
New php-forum User
 
Posts: 16
Joined: Fri May 25, 2012 6:05 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.