itbeings
06-18-2007, 04:00 AM
What function can I use to create a thumbnail for any image like GIF PNG and JPEG? I know how I can for each but I need to know if it's possible for all type.
Thanks in advance.
Thanks in advance.
|
Click to See Complete Forum and Search --> : Thumbnail for any Image type itbeings 06-18-2007, 04:00 AM What function can I use to create a thumbnail for any image like GIF PNG and JPEG? I know how I can for each but I need to know if it's possible for all type. Thanks in advance. bokeh 06-18-2007, 04:22 AM function resize_maintain_transparency($source, $destination = null, $w = 125, $h = 125, $quality = 100) { $details = @getimagesize($source) or die("I cannot open $source"); $type = preg_replace('@^.+(?<=/)(.+)$@', '$1', $details['mime']); eval('$source = imagecreatefrom'.$type.'($source);'); if($details[0] < $details[1]) { $w = round(($h / $details[1]) * $details[0]); } else { $h = round(($w / $details[0]) * $details[1]); } if(imageistruecolor($source)) { $slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions'); imageAlphaBlending($slate, false); imageSaveAlpha($slate, true); } else { $slate = @imagecreate($w, $h) or die('Invalid thumbnail dimmensions'); if(false !== ($trans = @imagecolorsforindex($source, imagecolortransparent($source)))) { $trans = ImageColorAllocate($slate, $trans['red'], $trans['green'], $trans['blue']); imagefilledrectangle($slate, 0, 0, $w - 1, $h - 1, $trans); imagecolortransparent($slate, $trans); } } imagecopyresampled($slate, $source, 0, 0, 0, 0, $w, $h, $details[0], $details[1]); $destination or header('Content-Type: '.$details['mime']); eval('@image'.$type.'($slate'.(($type=='jpeg')?',$destination,$quality':($destination?',$destination ':'')).');'); imagedestroy($source); imagedestroy($slate); $destination or die; } itbeings 06-19-2007, 02:13 AM Thanks Bokeh, it really works the way I want it too. In a case where U save image as it name with extension i.e if a file is named SHIP.png and you save it as SHIP(without the png, which will make it just a file), the function did not work perhaps it does not recognizes the file type. Anyway, thanks. itbeings 06-19-2007, 02:56 AM I have a problem with this code. When I tested it as a single file it worked but on getting where am to use it, it does not work. All I could see was lots of ���x���x���9d6��� �IDATx�ݽy�e�}��9����z�j�����MqIQ�Hm�dY�W���3�"x<� 9��`$A6ǁ�vhQ�N� �آ,[�DJ��5����T��{�9����z���I����w�s��=�������=�m�C~s�~���a���,C �类���0�u�=Ӱ�v���������w9.�R�n����_�O���n�q�{-�Z��r�����5 [W�w�={��uyo�a;�A/}�u߉�y���IHK{�-���o�����i�����!�X^�`��^�0����N �{�����Br�+��Խ[Ż�W��n������Pݻ�&?�u�A尶���<����K݃��s7�䧺�; U���~�?Ƞc?��u��꾛nҽJ�{�n����;��^��w��m�������w3�w^������ߗ@�2'�,��纎+�# �1Zi��:�v�!�{^N_�җ���ls��;����a�ߗu�+��e�RwgNk�1)��R:�{�w�uܒp��B�Ƙ5!�[`���w\�}K��a��2��{{{�1�322�Z-���0� ;砺���ߧ����M�A���h4����k���4�������a8g���� ��u�tp\'�n��6h�}�*0W���1+Aܑ�sKJ��n��a��1�N�� šU(|�q�/~���e�5���H���<��q�E I�&C�RmPZ�u�9�@ ��,`�@)E�}�ot�ݍ0״�+A�)�V�1˝Ng��v��}�o����Q(:�NG�_���RqwS����O}ݡ6 Any help? bokeh 06-19-2007, 03:00 AM Post the code that is calling the function. itbeings 06-19-2007, 03:24 AM define('Imag', 'http://localhost/Site/Images/'); //$pR['ImageName'] is the file name, like Ship.png $avL = Imag.$pR['ImageName']; thumbNail($avL, $destination = null, $w = 120, $h = 120, $quality = 100); bokeh 06-19-2007, 05:20 AM thumbNail($avL, $destination = null, $w = 120, $h = 120, $quality = 100); That's wrong; it should look like this: thumbNail($avL, null, 120, 120, 100); But what are you doing? Are you trying to output multiple files. Or are you trying to save them? itbeings 06-19-2007, 05:32 AM That's wrong; it should look like this: thumbNail($avL, null, 120, 120, 100); But what are you doing? Are you trying to output multiple files. Or are you trying to save them? It doesn't rally matters Bokeh but your are right. All the same, when I can it to what you wrote. I tested it outside my code and it worked but by calling the function in the middle of my code, all I could see is alot of what I pasted earlier. bokeh 06-19-2007, 05:40 AM That means your code is outputing something to the browser before calling this function. Do you know you can't successful output text and images on the same request? itbeings 06-19-2007, 06:09 AM So what do you think I can do to create the thumbnail? I have to resize alot of images to different sizes. itbeings 06-20-2007, 08:26 AM ??? bokeh 06-21-2007, 01:32 AM I have to resize alot of images to different sizes.You should be saving them to file, not outputing them. itbeings 06-23-2007, 12:48 AM Okay. which mean $destination won't have to be null. When declaring the destination path, should it be relative or absolute? Thanks. bokeh 06-24-2007, 03:33 PM should it be relative or absolute?That's for you to decide. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |