| | |
Square Image Thumbnail
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
So i found a script that does what I want but I'm having trouble "implementing" it. Basically I have all the image file names stored in my table and i want them to all display (the ones uploaded by the particular user logged in) on a page.
Of course I don't want them enormous, just small thumbnail images would do. I don't want them clickable or anything, i don't even want them to enlarge. But because of the whole portrait and landscape thing, i didn't want to hardcode the size in html. so, after searching i found this script:
here's how I'm calling the function:
(that's in a while statement)
i get a page full of wingdings and it says i'm also missing an argument. can anyone help?? the directions with this script really suck and don't explain anything.
thanks!
Of course I don't want them enormous, just small thumbnail images would do. I don't want them clickable or anything, i don't even want them to enlarge. But because of the whole portrait and landscape thing, i didn't want to hardcode the size in html. so, after searching i found this script:
PHP Syntax (Toggle Plain Text)
function createThumb($source,$dest) { $thumb_size = 150; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size,$thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height); imagejpeg($new_im,$dest,100); }
here's how I'm calling the function:
PHP Syntax (Toggle Plain Text)
<?php $path = "upload/$pic1"; echo "<img src=\"'".createThumb($path)."'\" />"; ?>
(that's in a while statement)
i get a page full of wingdings and it says i'm also missing an argument. can anyone help?? the directions with this script really suck and don't explain anything.
thanks!
Last edited by cscgal; May 31st, 2007 at 1:54 am. Reason: Excessive bbcode color removed
I see the problem. You can't call it in the img tag. That script creates a new file on the server, instead of returning an image. It doesn't return anything.
The function takes two arguments, the path to the image to change, and the path to store the changed image.
You need to put the path to the created image in the img tag.
Call the function, and then write the img tag on the next line. The src= should point to the same path as the changed image path.
The function takes two arguments, the path to the image to change, and the path to store the changed image.
You need to put the path to the created image in the img tag.
Call the function, and then write the img tag on the next line. The src= should point to the same path as the changed image path.
Daylight-saving time uses more gasoline
•
•
Join Date: Oct 2006
Posts: 42
Reputation:
Solved Threads: 4
what you could do is hardcore the the save directory into the function (as you have to save the image to the server, and this makes sense as you can then have it acting as a cache so that you only have to process the image once, rather than everytime the function is called which creates very high server load.) the create a file name dynamically.
This functions returns the file location so you can call it dynamically from within you img tag.
I will leave how to do the caching up to you (You do learn anything by someone doing it all for you.
But as a simple hint, you could create the filename from and md5 has of the source link and use the first 5 charaters of the md5 hash. This will ensure that you generate the same filename everytime you are passed the same source link. Then check in your file cache directory to see if that filename exists if it does just return the link without processing the image again. Simple
PHP Syntax (Toggle Plain Text)
function createThumb($source) { $image_save_dir = "/imagecache/"; $image_filename = substr(md5(microtime()),0,$length)."jpg"; $thumb_size = 150; $size = getimagesize($source); $width = $size[0]; $height = $size[1]; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_im = ImageCreatetruecolor($thumb_size,$thumb_size); $im = imagecreatefromjpeg($source); imagecopyresampled($new_im,$im,0,0,$x,$y,$thumb_size,$thumb_size,$width,$height); imagejpeg($new_im,$image_save_dir.$image_filename,100); return $image_save_dir.$image_filename; }
This functions returns the file location so you can call it dynamically from within you img tag.
I will leave how to do the caching up to you (You do learn anything by someone doing it all for you.
But as a simple hint, you could create the filename from and md5 has of the source link and use the first 5 charaters of the md5 hash. This will ensure that you generate the same filename everytime you are passed the same source link. Then check in your file cache directory to see if that filename exists if it does just return the link without processing the image again. Simple
![]() |
Similar Threads
- Generate Thumbnail images on the fly. (PHP)
- image rotation (C)
- error while image thumbnail processing (PHP)
- php mysql image again PLEASE HELP (PHP)
- Php Mysql Image Question (PHP)
- php image resize quality (PHP)
Other Threads in the PHP Forum
- Previous Thread: Creating an event or an action to a button.
- Next Thread: Scrolling display is blurred
| Thread Tools | Search this Thread |
apache api array basic beginner broken cache cakephp class cms code computing confirm countingeverycharactersfromastring cron curl customizableitems database date delete dynamic echo email error fcc file filter folder form forms forum freelancing function functions gc_maxlifetime google header headmethod howtowriteathesis href htaccess html iframe image include incode ip javascript joomla limit link login malfunction match memmory memory menu method mod_rewrite multiple mysql navigation neutrality oop pagerank parsing paypal pdf php phpmysql query question random recursiveloop root script search select server sessions sms snippet soap source space sql support! system table template thesishelp trouble tutorial upload url variable video web window.onbeforeunload=closeme; youtube






