简体   繁体   中英

How can I crop and append an image in a single step?

My aim is to crop an image from right side and append another image to cropped image at the bottom in a single step . What I mean single step is for ex, I used following code to crop image

$ini_filename = "/var/www/html/genome/family/$heatmap";
$im = imagecreatefrompng($ini_filename);

$ini_x_size = getimagesize($ini_filename )[0];
$ini_y_size = getimagesize($ini_filename )[1];

$to_crop_array = array('x' =>0 , 'y' => 0, 'width' => 1216, 'height'=> $width);
$thumb_im = imagecrop($im, $to_crop_array);

imagepng($thumb_im, "/var/www/html/genome/family/$heatmap", 0);

Now, I would like to append another image at the bottom of cropped image before saving to a directory . I found useful code for image appending here . But I am not understanding how can I append an image to the cropped image before executing the line: imagepng($thumb_im, "/var/www/html/genome/family/$heatmap", 0); . Or should I follow crop image, save, again open and append? Can anyone please give suggestion?

1) Create larger image with height+20

http://www.php.net/manual/en/function.imagecreatetruecolor.php

2) Copy the first image and the second image to the larger image

http://www.php.net/manual/en/function.imagecopy.php

3) Save it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM