dongsui3297 2009-11-12 04:36
浏览 28
已采纳

使用PHP脚本将多个映像连接到一个映像

I have this test page http://thechozenfew.net/projects/write_font.php that generates the text in the input box as a font. Each letter is a different picture, How would i join all these pictures into one image with a php script?

This what i've tried so far but the images appear on top of each other.

Header ("Content-type: image/gif"); 

$image1Url = "../images/avatar.png";
$image2Url = "../images/key.png";
$image3Url = "../images/safari.png";
$image1 = imageCreateFromPNG($image1Url);
$image2 = imageCreateFromPNG($image2Url);
$image3 = imageCreateFromPNG($image3Url);

$colorTransparent = imagecolorat($image1, 0, 0);
imageColorTransparent ($image1, $colorTransparent);

$colorTransparent = imagecolorat($image2, 0, 0);
imageColorTransparent ($image2, $colorTransparent);

$colorTransparent = imagecolorat($image3, 0, 0);
imageColorTransparent ($image3, $colorTransparent);

imageCopyMerge($image1, $image2, 0, 0, 0, 0, 96, 96, 100);

imageCopyMerge($image1, $image3, 0, 0, 0, 0, 96, 96, 80);

ImagePng ($image1);


ImageDestroy ($image1);
ImageDestroy ($image2);
  • 写回答

2条回答 默认 最新

  • dtj4307 2009-11-14 03:53
    关注

    So here what i ended up with

    <?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);
    ?>
    

    The Live Link http://thechozenfew.net/projects/font/ImageMerge.php?name=it%20works

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog