Thumbnail

Post your suggestions for the script here.

Thumbnail

Postby chrisw » Sun Jan 29, 2006 4:40 pm

Hello,



I would like to make thumbnails with gd1 or 2.

I have the code to do this but i don't know how to implement this in images.mdu



Can someone help?



Code:



<?php

function make_thumb ($img_src, $img_th)

{

// some configuration, please match to your server settings



$gd_version = 2;

$thumb_on = 'x';

$thumb_size = 100;

$quality = 30;

$img_size = GetImageSize ($img_src);

$img_in = ImageCreateFromJPEG ($img_src);

if ($thumb_on == 'y')

{

$img_x = ($thumb_size/$img_size[1]) * $img_size[0];

$img_y = $thumb_size;

}

else

{

$img_y = ($thumb_size/$img_size[0]) * $img_size[1];

$img_x = $thumb_size;

}

if ($gd_version == '1')

{

$img_out = ImageCreate($img_x, $img_y);

ImageCopyResized ($img_out, $img_in, 0, 0, 0, 0, $img_x, $img_y, $img_size[0], $img_size[1]);

}

elseif ($gd_version == '2')

{

$img_out = ImageCreateTrueColor($img_x, $img_y);

ImageCopyResampled ($img_out, $img_in, 0, 0, 0, 0, $img_x, $img_y, $img_size[0], $img_size[1]);

}

ImageJPEG ($img_out, $img_th, $quality);

ImageDestroy ($img_out);

ImageDestroy ($img_in);

}

if (isset ($_FILES['image']['name']))

{

$fn = $_FILES['image']['name'];

$src = 'images/'.$fn;

$th = 'thumbs/'.$fn;

if (!@move_uploaded_file ($_FILES['image']['tmp_name'], $src)) die ('Can not upload file...');

make_thumb ($src, $th);

echo "Done!<BR>Original Image:<img src=\"$src\"><BR>Thumbnail Image:<img src=\"$th\">";

}

?>

<form name="form" id="form" action="$PHP_SELF?mod=images" method="post" enctype="multipart/form-data">Thumbnail this file: <input name="image" type="file"><input type="submit" value="Send File"></form>



Regards,



Chris
chrisw
 
Posts: 2
Joined: Thu Jan 26, 2006 11:27 am

Postby FI-DD » Sun Jan 29, 2006 7:49 pm

Why don't you use the built-in thumbnail function?
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby chrisw » Sun Jan 29, 2006 9:26 pm

Because the standard function does not make that nice thumbnails.

The qauality is not so good as with GD 2.
chrisw
 
Posts: 2
Joined: Thu Jan 26, 2006 11:27 am

Postby FI-DD » Mon Jan 30, 2006 12:48 am

Open images.mdu and change imagecopyresize to imagecopyresampled.



That's it. And you are right, the quality is better. :wink:



(I will change this in the download file as well.)
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby samiro » Mon Jan 05, 2009 1:12 pm

in my file - uts is set as imagecopyresampled
but how can i make it better...
the compress pf the jped in very high...

i want a quality like 90-95%

thank you
[/code]
User avatar
samiro
 
Posts: 103
Joined: Sun Apr 20, 2008 1:52 pm
Location: IL

Postby FI-DD » Thu Feb 05, 2009 3:42 pm

Right now the script uses the default compression rate which should be about 75%.

To change it you have to add the compression rate as a third parameter in the function.

For example now:
Code: Select all
imagejpeg($image, $thumb_in);


and after:
Code: Select all
imagejpeg($image, $thumb_in, 95);


Do this for all occurrances of imagejpeg() in images.mdu.
User avatar
FI-DD
Admin
 
Posts: 2971
Joined: Thu Sep 22, 2005 11:27 am
Location: Germany

Postby samiro » Thu Mar 18, 2010 10:14 pm

after - or replace ?
User avatar
samiro
 
Posts: 103
Joined: Sun Apr 20, 2008 1:52 pm
Location: IL

Postby eberswine » Fri Mar 19, 2010 12:52 am

find
Code: Select all
imagejpeg($image, $thumb_in);

replace
Code: Select all
imagejpeg($image, $thumb_in, 95);


replace all occurrences
User avatar
eberswine
 
Posts: 281
Joined: Thu Apr 26, 2007 7:23 pm

Postby samiro » Fri Mar 19, 2010 7:17 am

can i change even

imagepng($image, $thumb_in);
and
imagegif($image, $thumb_in);

to

imagepng($image, $thumb_in, 95);
imagegif($image, $thumb_in, 95);
User avatar
samiro
 
Posts: 103
Joined: Sun Apr 20, 2008 1:52 pm
Location: IL

Postby samiro » Fri Mar 19, 2010 7:20 am

did i have to change also this ?

Code: Select all
case 'jpg':
$original_image = imageCreateFromJPEG($thumb_in);
break;
User avatar
samiro
 
Posts: 103
Joined: Sun Apr 20, 2008 1:52 pm
Location: IL

Postby eberswine » Fri Mar 19, 2010 2:38 pm

samiro..

what I would do, is upload some test gifs, jpgs and pngs... then after you upload them, just look at the properties of the picture and see the size in bytes or kb's... then, what I would do is make changes to your images.mdu page and then upload the same images again and see if the size in bytes or kb's went up!

That is all your after!
User avatar
eberswine
 
Posts: 281
Joined: Thu Apr 26, 2007 7:23 pm


Return to Suggestions



Who is online

Users browsing this forum: No registered users and 0 guests

cron