Создать изображение в профиле PHP после фона

У меня проблема, я создаю аватарку на рамке. Но я хочу сделать PNG изображение профиля внутренней рамки.

$picurl = "profile_pic_resize/$get_id.jpg";      
$frame = imagecreatefrompng($cover_select);
$img = imagecreatefromjpeg($picurl);


imagealphablending($frame, false);
imagesavealpha($frame, true);

imagecopy($frame, $img, 20, 137, 0, 40, 130, 160); //have to play with these numbers for it to work for you, etc.

$getid = $_GET['id'];

imagepng($frame,"ready_pics/$getid.png");

imagedestroy($frame);
imagedestroy($img);

1 ответ

Изображение с камеры

Камера с дисплеем

Изображение девушки

милая девушка

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

?>

Результат:

Окончательный результат обработки php

Другие вопросы по тегам