且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用PHP脚本将多个图像合并为一个

更新时间:2023-01-08 16:28:41

所以我在这里结束了

<?php
header('Content-type: image/png');

function imageComposeAlpha( &$src, &$ovr, $ovr_x, $ovr_y, $ovr_w = false, $ovr_h = false, $opc = 127){
 imagecopy($src, $ovr, $ovr_x, $ovr_y, 0, 0, imagesx($ovr), imagesy($ovr) );
}

////////////////////////---////////-----------------------------------

$url = "../../images/socom_font/normal/Socom";

//Covert the String iinto an Array
 $letter = str_split(strtoupper ($_GET['name']));
//Populate Letters Image Path
 foreach($letter as $a){
   //exeptions
  if($a == "?"){ $a = "Question"; }
  if($a == "/"){ $a = "Slash"; }
  if($a == "%"){ $a = "Percent"; }
  if($a == " "){ $a = "Space"; }
  $image[] = $url.$a.".png";
 }unset($a); 
//Create the Letters Image Objects
 foreach($image as $a){
  $image['obj'][] = imageCreateFromPNG($a);
 }unset($a);
//calculate Canvas Width
 foreach($image['obj'] as $a){
  if(!isset($canvasW)){ $canvasW = 0; }
  $canvasW = imagesx($a) + $canvasW;
 }unset($a);
//Create Canvas
 $photoImage = imagecreatetruecolor($canvasW,100);
 imagesavealpha($photoImage, true);
 $trans_color = imagecolorallocatealpha($photoImage, 0, 0, 0, 127);
 imagefill($photoImage, 0, 0, $trans_color);

//Merge Images
 foreach($image['obj'] as $a){
  $width = ceil(imagesx($a));
  if(!isset($offset)){ $offset = 1; }

  imageComposeAlpha($photoImage, $a, $offset, 0,$width,100);

  if($offset >= 1){
   $offset = $offset + $width;
  }
 }unset($a);
// Save it
 //Imagepng($photoImage, 'done.png'); 
// Output to browser 
 Imagepng($photoImage); 

//Destroy all Image Objects
 foreach($image['obj'] as $a){
  ImageDestroy($a);
 }
 ImageDestroy($photoImage);
?>

实时链接 http://thechozenfew.net/projects/font/ImageMerge.php?name = it%20works