-
Function overlayjpg ($ imgsrc, $ imgdst, $ width, $ height = "")
- {
- // $ Imgsrc jpg format image path $ imgdst jpg format Image save file name $ imgwidth to change the width $ imgheight to change the height
- // Obtain the image width and height
- $ Arr = getimagesize ($ imgsrc );
- // Calculate the x axis of the image.
- $ Img_X = ($ width-$ arr [0])/2;
- If ($ height = ""){
- $ Heights = $ arr [1];
- $ Img_Y = 0;
- }
- Else {
- If ($ height <= $ arr [1]) {
- $ Heights = $ arr [1];
- $ Img_Y = 0;
- }
- Else {
- $ Heights = $ height;
- $ Img_Y = ($ height-$ arr [1])/2;
- }
- }
-
// $ W = $ arr [0];
- // $ H = $ arr [1];
- // Create image and define colors
- $ Image = imagecreatetruecolor ($ width, $ heights); // create a colored Basemap
- $ Bg = imagecolorallocate ($ image, 255,255,255 );
- Imagefill ($ image, 0, 0, $ bg );
- $ Imgsrc = LoadIMG ($ imgsrc, $ arr ['Mime ']);
- Imagecopy ($ image, $ imgsrc, $ img_X, $ img_Y, 0, 0, $ arr [0], $ arr [1]);
- Imagejpeg ($ image, $ imgdst, 90 );
- // Imagedestroy ($ image );
- }
- // Load the background image
- Function LoadIMG ($ imgname, $ mime)
- {
- If ($ mime = "image/gif "){
- $ Im = @ imagecreatefromgif ($ imgname);/* Attempt to open */
- }
- Elseif ($ mime = "image/png "){
- $ Im = @ imagecreatefrompng ($ imgname);/* Attempt to open */
- }
- Else {
- $ Im = @ imagecreatefromjpeg ($ imgname);/* Attempt to open */
- }
- If (! $ Im) {/* See if it failed */
- $ Im = imagecreatetruecolor (150, 30);/* Create a blank image */
- $ Bgc = imagecolorallocate ($ im, 255,255,255 );
- $ Tc = imagecolorallocate ($ im, 0, 0, 0 );
- Imagefilledrectangle ($ im, 0, 0,150, 30, $ bgc );
- /* Output an errmsg */
- Imagestring ($ im, 1, 5, 5, "Error loading $ imgname", $ tc );
- }
- Return $ im;
- }
|