PHP generates image thumbnails. PHP generates image thumbnails: to use PHP to generate image thumbnails, make sure that your PHP Server has installed the GD2 graphics library and uses a class to generate image thumbnails, see the following section for the class source code to call this PHP to generate image thumbnails:
To use PHP to generate image thumbnails, ensure that the GD2 graphics library is installed on your PHP server.
Use a class to generate image thumbnails. the source code of the class is described below.
Call this method:
Resizeimage = new resizeimage ("Image source file address", "200", "100", "0", "thumbnail address ");
// A thumbnail can be generated with only one sentence above. the source file and the thumbnail address can be the same, and 200,100 represents the width and height respectively.
// Use the following classes to generate image thumbnails,
Class resizeimage
{
// Image type
Var type;
// Actual width
Var width;
// Actual height
Var height;
// Change the width
Var resize_width;
// The height after the change
Var resize_height;
// Whether to cut the image
Var cut;
// Source image
Var srcimg;
// Target Image address
Var dstimg;
// Temporarily created image
Var im;
Function resizeimage (img, wid, hei, c, dstpath)
{
This-> srcimg = img;
This-> resize_width = wid;
This-> resize_height = hei;
This-> cut = c;
// Image type
This-> type = strtolower (substr (strrchr (this-> srcimg, "."), 1 ));
// Initialize the image
This-> initi_img ();
// Target Image address
This-> dst_img (dstpath );
//--
This-> width = imagesx (this-> im );
This-> height = imagesy (this-> im );
// Generate an image
This-> newimg ();
ImageDestroy (this-> im );
}
Function newimg ()
{
// Ratio of the changed image
Resize_ratio = (this-> resize_width)/(this-> resize_height );
// Ratio of the actual image
Ratio = (this-> width)/(this-> height );
If (this-> cut) = "1 ")
// Cut the image
{
If (ratio> = resize_ratio)
// High priority
{
Newimg = imagecreatetruecolor (this-> resize_width, this-> resize_height );
Imagecopyresampled (newimg, this-> im, 0, 0, 0, 0, this-> resize_width, this-> resize_height, (this-> height) * resize_ratio ), this-> height );
ImageJpeg (newimg, this-> dstimg );
}
If (ratio
// The width is preferred.
{
Newimg = imagecreatetruecolor (this-> resize_width, this-> resize_height );
Imagecopyresampled (newimg, this-> im, 0, 0, 0, 0, this-> resize_width, this-> resize_height, this-> width, (this-> width) /resize_ratio ));
ImageJpeg (newimg, this-> dstimg );
}
}
Else
// No cut Chart
{
If (ratio> = resize_ratio)
{
Newimg = imagecreatetruecolor (this-> resize_width, (this-> resize_width)/ratio );
Imagecopyresampled (newimg, this-> im, 0, 0, 0, 0, this-> resize_width, (this-> resize_width)/ratio, this-> width, this-> height );
ImageJpeg (newimg, this-> dstimg );
}
If (ratio
{
Newimg = imagecreatetruecolor (this-> resize_height) * ratio, this-> resize_height );
Imagecopyresampled (newimg, this-> im, 0, 0, 0, 0, (this-> resize_height) * ratio, this-> resize_height, this-> width, this-> height );
ImageJpeg (newimg, this-> dstimg );
}
}
}
// Initialize the image
Function initi_img ()
{
If (this-> type = "jpg ")
{
This-> im = imagecreatefromjpeg (this-> srcimg );
}
If (this-> type = "gif ")
{
This-> im = imagecreatefromgif (this-> srcimg );
}
If (this-> type = "png ")
{
This-> im = imagecreatefrompng (this-> srcimg );
}
}
// Target Image address
Function dst_img (dstpath)
{
Full_length = strlen (this-> srcimg );
Type_length = strlen (this-> type );
Name_length = full_length-type_length;
Name = substr (this-> srcimg, 0, name_length-1 );
This-> dstimg = dstpath;
// Echo this-> dstimg;
}
}
?>
Ghost needs to use PHP to generate image thumbnails. make sure that the GD2 graphics library is installed on your PHP Server and uses a class to generate image thumbnails. the class source code can be called below...