Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
Showing results for
PHP: Dynamically Creating Thumbnails
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- PHP: Dynamically Creating Thumbnails
PHP: Dynamically Creating Thumbnails
11-09-2007 10:24 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Hello there,
I would like to dynamically create some image thumbnails. I have written a php file, getThumbnail.php, that I call during every iteration of a for loop. However, the unexpected result is thus:
all the thumbnails are the same, they are all of the last image in the directory.
Other than that, the result is as expected.
Does anyone know why this happens? How can I fix it?
Thanks in advance,
Logical
Code:
index.php:
getThumbnail.php:
I would like to dynamically create some image thumbnails. I have written a php file, getThumbnail.php, that I call during every iteration of a for loop. However, the unexpected result is thus:
all the thumbnails are the same, they are all of the last image in the directory.
Other than that, the result is as expected.
Does anyone know why this happens? How can I fix it?
Thanks in advance,
Logical
Code:
index.php:
for($i = 1; intval($i) <= intval($total); $i = intval($i) + 1)
{
$photo = $album . $i;
$filename = $photo . '.jpg';
$image = './' . $album . '/' . $filename;
$_SESSION['image'] = $image;
<img src="getThumbnail.php" />
}
getThumbnail.php:
session_start();
$file = $_SESSION['image'];
$size = 0.45;
list($width, $height) = getimagesize($file);
$modwidth = 80;
$modheight = 80;
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, null, 100);
Message 1 of 3
(1,479 Views)
2 REPLIES 2
Re: PHP: Dynamically Creating Thumbnails
11-09-2007 10:50 AM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
You don't need the intval in the for loop.
Do you have a session_start() in index.php?
I'm note sure what you are trying to do by having HTML code (<img src="getThumbnail.php">) within the php section as that will not work.
I would pass the filename as a parameter rather than using $_SESSION[] as its likely the $_SESSION[] has not been saved to disk before it is used within getThumbnail.php
index.php
getThumbnail.php
Do you have a session_start() in index.php?
I'm note sure what you are trying to do by having HTML code (<img src="getThumbnail.php">) within the php section as that will not work.
I would pass the filename as a parameter rather than using $_SESSION[] as its likely the $_SESSION[] has not been saved to disk before it is used within getThumbnail.php
index.php
for($i = 1; $i <= $total; $i += 1)
{
$photo = $album . $i;
$filename = $photo . '.jpg';
$image = './' . $album . '/' . $filename;
?>
<img src="getThumbnail.php?<?php echo $image ?>" /><br>
<?php
}
getThumbnail.php
$file = $_GET['file'];
$size = 0.45;
list($width, $height) = getimagesize($file);
$modwidth = 80;
$modheight = 80;
$tn = imagecreatetruecolor($modwidth, $modheight);
$image = imagecreatefromjpeg($file);
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height);
imagejpeg($tn, null, 100);
Message 2 of 3
(342 Views)
Re: PHP: Dynamically Creating Thumbnails
11-09-2007 2:24 PM
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Report to Moderator
Thanks. It all works fine.
Message 3 of 3
(342 Views)
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Plusnet Community
- :
- Forum
- :
- Help with my Plusnet services
- :
- Everything else
- :
- PHP: Dynamically Creating Thumbnails