andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


Making this script working on GD 1.6 or higher ?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator
View previous topic :: View next topic  
Author Message
philos
Newbie


Joined: 21 May 2003
Posts: 6
Location: Strasbourg

PostPosted: Sat May 24, 2003 6:04 am    Post subject: Making this script working on GD 1.6 or higher ? Reply with quote

Hello,

I test this script successfuly on my own server with gd2 library,
but my webhosting company "Claranet" hasn't got yet the gd2 library installed on their server, is it possible or absolutely impossible to write a version of this class compatible with the older version of gd ?

kind regards

Philippe
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Sat May 24, 2003 6:19 am    Post subject: Reply with quote

Hi,

For the most part you should be able to replace the ImageCreateTrueColor for ImageCreate and change ImageCopyResampled to ImageCopyResize. 1.6.2 can still have PNG support, so you chould be able to still use the background colour option. Hmm.. The quality of the resized images is going to be POOR, though. I've used the bicubic resampling function from the php.net website (a comment from someone), which seems to work well. I just implemented it for a client, not using this class or anything, but the function works well. Here are the two I put into the client's code:

Code:
   // port to PHP by John Jensen July 10 2001 -- original code (in C, for the PHP GD Module) by jernberg@fairytale.se

   function ImageCopyResampleBicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
   {
      for ($i = 0; $i < @imagecolorstotal($src_img); $i++)
      {
         $colors = @ImageColorsForIndex ($src_img, $i);
         @ImageColorAllocate ($dst_img, $colors['red'], $colors['green'], $colors['blue']);
      }
      $scaleX = ($src_w - 1) / $dst_w;
      $scaleY = ($src_h - 1) / $dst_h;
      $scaleX2 = $scaleX / 2.0;
      $scaleY2 = $scaleY / 2.0;
      for ($j = $src_y; $j < $dst_h; $j++)
      {
         $sY = $j * $scaleY;
         for ($i = $src_x; $i < $dst_w; $i++)
         {
            $sX = $i * $scaleX;
            $c1 = @ImageColorsForIndex ($src_img, @ImageColorAt ($src_img, (int) $sX, (int) $sY + $scaleY2));
            $c2 = @ImageColorsForIndex ($src_img, @ImageColorAt ($src_img, (int) $sX, (int) $sY));
            $c3 = @ImageColorsForIndex ($src_img, @ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY + $scaleY2));
            $c4 = @ImageColorsForIndex ($src_img, @ImageColorAt ($src_img, (int) $sX + $scaleX2, (int) $sY));
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
            $color = @ImageColorClosest ($dst_img, $red, $green, $blue);
            @ImageSetPixel ($dst_img, $i + $dst_x, $j + $dst_y, $color);
         }
      }
   }

   /*
   Function derived from ImageCopyResampleBicubic()
   Original code in C, for the PHP GD Module by jernberg@fairytale.se
   Port to PHP by John Jensen July 10 2001
   Updated by tim@smoothdeity.com
   Re-edited & optimized by TCK
   */
   function ImageResizeBicubic(&$src, $x, $y)
   {
      $dst=@ImageCreate($x, $y);
      $pals=@ImageColorsTotal ($src);
      for ($i=0; $i<$pals; $i++)
      {
         $colors=@ImageColorsForIndex ($src, $i);
         @ImageColorAllocate ($dst, $colors['red'], $colors['green'], $colors['blue']);
      }
      $scX  =(@imagesx ($src)-1)/$x;
      $scY =(@imagesy ($src)-1)/$y;
      $scX2 =intval($scX/2);
      $scY2 =intval($scY/2);
      for ($j = 0; $j < ($y); $j++)
      {
         $sY = intval($j * $scY);
         $y13 = $sY + $scY2;
         for ($i = 0; $i < ($x); $i++)
         {
            $sX = intval($i * $scX);
            $x34 = $sX + $scX2;
            $c1 = @ImageColorsForIndex ($src, @ImageColorAt ($src, $sX, $y13));
            $c2 = @ImageColorsForIndex ($src, @ImageColorAt ($src, $sX, $sY));
            $c3 = @ImageColorsForIndex ($src, @ImageColorAt ($src, $x34, $y13));
            $c4 = @ImageColorsForIndex ($src, @ImageColorAt ($src, $x34, $sY));
            $r = ($c1['red']+$c2['red']+$c3['red']+$c4['red'])/4;
            $g = ($c1['green']+$c2['green']+$c3['green']+$c4['green'])/4;
            $b = ($c1['blue']+$c2['blue']+$c3['blue']+$c4['blue'])/4;
            @ImageSetPixel ($dst, $i, $j, @ImageColorClosest ($dst, $r, $g, $b));
         }
      }
      return ($dst);
   }


Hope that helps.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Sat May 24, 2003 6:20 am    Post subject: Reply with quote

Of course, you could always hound Claranet to update their software, too. Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
philos
Newbie


Joined: 21 May 2003
Posts: 6
Location: Strasbourg

PostPosted: Sat May 24, 2003 6:54 am    Post subject: Reply with quote

Thanks a lot for this help !!

Of course I have hounded Claranet perhaps they will upgrade in few months but not now Sad

Philippe
Back to top
View user's profile Send private message Visit poster's website
philos
Newbie


Joined: 21 May 2003
Posts: 6
Location: Strasbourg

PostPosted: Sat May 24, 2003 7:50 am    Post subject: Reply with quote

Just a last thing, I don't want to abuse of your time Wink

so what I did :

add the function Image ImageCopyResampleBicubic in the class
and replace
@ImageCopyResampled
by
$this->ImageCopyResampleBicubic

then I replace
CreateImageTrueColor
by
CreateImage

I have no use of ImageResizeBicubic isn't it ?

Thanks in advance

Philippe
Back to top
View user's profile Send private message Visit poster's website
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Sat May 24, 2003 9:11 am    Post subject: Reply with quote

You don't have to use both functions, no. The first one, ImageCopyResampleBicubic, emulates the original ImageCopyResampled the most, with the same kind of parameters. The second is just a cut down version of the functions that is for resizing the images to a certain width/height.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
philos
Newbie


Joined: 21 May 2003
Posts: 6
Location: Strasbourg

PostPosted: Sat May 24, 2003 10:02 am    Post subject: Reply with quote

Ok it is decently working, but without the shadows.
With the shadows, the resulting image is uggly Wink

thanks a lot, I will do without shadows for the moment

Kind regards

Philippe
Back to top
View user's profile Send private message Visit poster's website
rophizz
Newbie


Joined: 21 Oct 2003
Posts: 2
Location: In da House ...

PostPosted: Tue Oct 21, 2003 7:40 am    Post subject: same problem ... Reply with quote

Hi folks,
I have the same problem as above ...

my gd version is 1.6 or higher ( from phpinfo )

i did not find a script on the net ( so far ... ) to solve my thumbnailing problem.

@amnuts : How can I use those 2 functions you posted above ...?
can you give me a little example ?

thx in advance ...
Rolling Eyes
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Oct 21, 2003 8:20 am    Post subject: Re: same problem ... Reply with quote

rophizz wrote:
Hi folks,
I have the same problem as above ...

my gd version is 1.6 or higher ( from phpinfo )

i did not find a script on the net ( so far ... ) to solve my thumbnailing problem.

@amnuts : How can I use those 2 functions you posted above ...?
can you give me a little example ?

thx in advance ...
Rolling Eyes


Hi there, and welcome to the baord.

Here's an example taken (almost) directly from work done for a client of a client...

In one file I have the bicubic function (listed above) with a secondary function that looks like this:

PHP:
<?php

    
function createThumbnail($input$output$size)
    {

        
$img ImageCreateFromJpeg($input);
        
        
// resize on width
        
if (@ImageSX($img) <= $size)
        {
            
$h = @ImageSY($img);
            
$w = @ImageSX($img);
        }
        else
        {
            
$h ImageSY($img) / (ImageSX($img) / $size);
            
$w $size;
        }
        
        
$dst ImageResizeBicubic($img$w$h);
        return (
ImageJPEG($dst$output80) ? TRUE FALSE);
    }

?>


Then in the file I use to upload the image (it's a news displayer which can optionally include an image), I have:

PHP:
<?php


// process images
if ($HTTP_POST_FILES['imageFile']['name'] && (strtolower($sf->file_extension($HTTP_POST_FILES['imageFile']['name'])) == "jpg"))
{
    
createThumbnail($HTTP_POST_FILES['imageFile']['tmp_name'], "{$newsVars['image_path']}/thumb_$insertID.jpg"120);
    
createThumbnail($HTTP_POST_FILES['imageFile']['tmp_name'], "{$newsVars['image_path']}/$insertID.jpg"200);
    @
unlink($HTTP_POST_FILES['imageFile']['tmp_name']);
}

?>


That's it... Pretty easy, huh? Obviously you could do a lot more with it (for example, use the resizing options in the dropshadow class), but this should give you a quick example of how the functions listed above could be used.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
rophizz
Newbie


Joined: 21 Oct 2003
Posts: 2
Location: In da House ...

PostPosted: Fri Oct 24, 2003 4:57 am    Post subject: yee ... Reply with quote

10x ... it works very fine now ... Very Happy Razz
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Drop Shadowed Thumbnail Creator All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group