/    Sign up×
Community /Pin to ProfileBookmark

Quick Thumbnails!

Whats the quickest way of creating thumbnails from an image, then when the user clicks the thumbnail, the full size version of the image is displayed?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@holidayDec 08.2007 — [code=php]
here's a php function that that I made, it will except PNG, GIF and JPEG/JPG file formats and will export to a JPEG/JPG.

<?php
//Creat Function: resize photo and save
function resize_photo_save($sourcefile, $destfile, $max_width = '', $max_height = '', $quality = '90')
{
//get image size
$size = getimagesize($sourcefile);

$width = $size[0];
$height = $size[1];

//set new size vars
$new_width = $width;
$new_height = $height;

//check width size
if($max_width)
{
if($new_width>$max_width)
{
$percent = $max_width / $new_width;
$new_height = $new_height * $percent;
$new_width = $max_width;
}
}

//check height size
if($max_height)
{
if($new_height>$max_height)
{
$percent = $max_height / $new_height;
$new_height = $max_height;
$new_width = $new_width * $percent;
}
}

//round width and height to nerest whole number
$new_width = round($new_width);
$new_height = round($new_height);

//determin image type
$image_type = exif_imagetype($sourcefile);

if($image_type=='1')
{
$img_src = imagecreatefromgif( $sourcefile );
}

if($image_type=='2')
{
$img_src = imagecreatefromjpeg( $sourcefile );
}

if($image_type=='3')
{
$img_src = imagecreatefrompng( $sourcefile );
}

//check for valid image type
if(!$img_src)
{
return '0';
}
else
{
//create new image, resample old image, save new image and destroy all temp files
$img_dst = imagecreatetruecolor( $new_width, $new_height);
imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
if(!imagejpeg($img_dst, $destfile, $quality))
{
return '0';
}
else
{
return '1';
}
imagedestroy($img_src);
imagedestroy($img_dst);
}
}

?>
[/code]
Copy linkTweet thisAlerts:
@DysanauthorDec 08.2007 — How do I do this through just html? Creating the thumbnails manually, then display the full size image on a different page when the thumbnail is clicked?
Copy linkTweet thisAlerts:
@holidayDec 08.2007 — [code=html]<a href="big_image.jpg" target="_blank"><img src="small_image.jpg" /></a>[/code]
×

Success!

Help @Dysan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...