/    Sign up×
Community /Pin to ProfileBookmark

Thumbnail image

Is there any script to compress the original image to thumbnail image?

If it so plz help me!!!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsFeb 16.2006 — here is an example, it produces thumbnails like imageshack[code=php]function make_thumb($src_path)
{
global $config;

if(!file_exists($src_path))
{
return false;
}
list($src_x, $src_y, $type,) = getimagesize($src_path);
$ratio = $src_x / $src_y;
$dst_x = $config['thumbnail_maxsize'];
$dst_y = $config['thumbnail_maxsize'];

if($ratio > 1)
{
$dst_y /= $ratio;
}
else if($ratio < 1)
{
$dst_x *= $ratio;
}
$sp = 0;
$direction = 0;

switch($type)
{
case 1:
$src_im = imagecreatefromgif($src_path);
break;
case 2:
$src_im = imagecreatefromjpeg($src_path);
break;
case 3:
$src_im = imagecreatefrompng($src_path);
break;
case 15:
$src_im = imagecreatefromwbmp($src_path);
break;
case 16:
$src_im = imagecreatefromxbm($src_path);
break;
default:
$src_im = false;
}
if(!is_resource($src_im))
{
return false;
}
if($config['thumbnail_showinfo'])
{
$sp = 15;
$text = "{$src_x}x{$src_y} " .round(@filesize($src_path) / 1024). "kb";
$font = 2;
$text_width = imagefontwidth($font) * strlen($text);

if($text_width > $dst_x)
{
$direction = 1;
}
}
// add 2 pixels for border and 15 for text space
if(!$direction)
{
$dst_im = imagecreatetruecolor($dst_x + 2, $dst_y + $sp + 2);
}
else
{
$dst_im = imagecreatetruecolor($dst_x + $sp + 2, $dst_y + 2);
}
list($r, $g, $b) = explode(',', $config['thumbnail_bgcolor']);
$bg = @imagecolorallocate($dst_im, $r, $g, $b);
@imagefill($dst_im, 0, 0, $bg);
@imagecopyresampled($dst_im, $src_im, 1, 1, 0, 0, $dst_x, $dst_y, $src_x, $src_y);
@imagedestroy($src_im);

if($config['thumbnail_showinfo'])
{
list($r, $g, $b) = explode(',', $config['thumbnail_fgcolor']);
$fg = @imagecolorallocate($dst_im, $r, $g, $b);

if(!$direction)
{
$center = round((($dst_x + 2) - $text_width) / 2);
@imagestring($dst_im, $font, $center, $dst_y + 2, $text, $fg);
}
else
{
$center = round(((($dst_y + 2) - $text_width) / 2) + $text_width);
@imagestringup($dst_im, $font, $dst_x + 2, $center, $text, $fg);
}
}
$x = pathinfo($src_path);
$dst_path = $x['dirname'] . 'th_' . $x['basename'] . '.jpg';
$r = @imagejpeg($dst_im, $dst_path, $config['thumbnail_quality']);
@imagedestroy($dst_im);
return $r;
}[/code]
Copy linkTweet thisAlerts:
@bokehFeb 16.2006 — [code=php]fswitch($type)
{
case 1:
$src_im = imagecreatefromgif($src_path);
break;
case 2:
$src_im = imagecreatefromjpeg($src_path);
break;
case 3:
$src_im = imagecreatefrompng($src_path);
break;
case 15:
$src_im = imagecreatefromwbmp($src_path);
break;
case 16:
$src_im = imagecreatefromxbm($src_path);
break;
default:
$src_im = false;
}[/code]
[/QUOTE]
That is not necessary. You could use the following instead:[code=php]$src_im = @imagecreatefromstring(@file_get_contents($src_path)) or die('Not an image');[/code]
Copy linkTweet thisAlerts:
@bokehFeb 16.2006 — I posted a [URL=http://www.webdeveloper.com/forum/showthread.php?t=93611#post505137]thumbnail function here[/URL] last week.
×

Success!

Help @jerry_29 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.18,
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,
)...