在背景后在PHP配置文件中创建图像

时间:2017-08-05 15:17:44

标签: php imagecreatefrompng

我有问题我在框架上创建个人资料图片。但我想制作PNG个人资料图片内框。

enter image description here

http.get

1 个答案:

答案 0 :(得分:0)

摄像机图像

Camera with display screen

女孩形象

pretty girl

<?php

    /* 
        Server base directory from which other directories follow
        Clearly this is unique to my system so it will need to be
        changed to suit environment.
    */
    $root='c:/wwwroot';

    /*
        In practice the image of the girl is likely to be chosen
        dynamically somehow - querystring, form submission, database etc
        so the paths will clearly need to be changed accordingly.
    */
    $images=new stdClass;
    $images->frame='/images/css/borders/camera_frame.png';
    $images->girl='/images/tmp/girl.jpg';

    /* Get the actual image size of the image containing the girl */
    list( $w, $h, $t, $a )=getimagesize( $root . $images->girl );

    /* Where (x,y) to position the girl */
    $px=49;
    $py=105;

    /* Final blend opacity */
    $opacity=100;


    /* 
        The dimensions of the camera screen onto 
        which the image of the girl will be 
        superimposed
    */
    $nw=236;
    $nh=154;


    /*
        x,y where to place image of girl
    */
    $x=0;
    $y=0;

    /*
        Create source images to manipulate
    */
    $target = imagecreatefrompng( $root . $images->frame );
    $girl = imagecreatefromjpeg( $root . $images->girl );
    $copy = imagecreatetruecolor( $nw, $nh );


    /*
        Resize image of girl to fit viewport of camera
    */
    imagecopyresampled( $copy, $girl, 0, 0, 0, 0, $nw, $nh, $w, $h );

    /*
        Merge the two images to form desired result
    */
    imagecopymerge( $target, $copy, $px, $py, $x, $y, $nw, $nh, $opacity );

    /*
        Output to browser and clean up
    */
    header('Content-Type: image/png');
    imagepng( $target);

    imagedestroy( $target );
    imagedestroy( $copy );
    imagedestroy( $girl );

?>

结果:

Final output from php processing