andreknieriem / photobooth

A photobooth Web-Application for raspberry pi with gphoto2
https://photobooth.andrerinas.de/
MIT License
300 stars 163 forks source link

New Collage Layout #164

Closed KH404 closed 2 years ago

KH404 commented 5 years ago

Is your feature request related to a problem? Please describe. On my own wedding we had a photobooth which had a 2x4 layout for the collage function. We likes the layout, because with one print you had the pictures twice. The print was cut in half, so you had two picture stripes. One was for the guest book and the other for the guests.

Describe the solution you'd like On my local code I implemented the layout for an older version. I am not into php, so it is not coded in a good way. It worked but the performance was bad. Unfortunately the code files are not matching with the new code structure so I attached the code parts which I implemented for the previous release. Maybe you can take it, improve it and add it as a new feature.

Describe alternatives you've considered If you do not like it, you can also omit the layout.

Example_of_the_new_layout

config.inc.php $config['collage_layout'] = '2x2'; // possible layouts are 2x2 and 2x4 (row x column)

index.php 'collage_layout' => [ 'type' => 'select', 'name' => 'collage_layout', 'placeholder' => 'collage_layout', 'options' => [ '2x2' => '2x2', '2x4' => '2x4', ], 'value' => $config['collage_layout'] ]

takePic.php

switch($layout) {
    case '2x2':
        // make collage
        list($width, $height) = getimagesize($collagePhoto[0]);
        $my_collage_height = $height * 2;
        $my_collage_width = $width * 2;
        $my_collage = imagecreatetruecolor($my_collage_width, $my_collage_height)
                or die("Kann keinen neuen GD-Bild-Stream erzeugen");
        $background = imagecolorallocate($my_collage, 0, 0, 0);
        imagecolortransparent($my_collage, $background);
        $collage_pic1 = imagecreatefromjpeg($collagePhoto[0]) or die("no imagcreate");
        imagecopy($my_collage, $collage_pic1, 0, 0, 0, 0, $width, $height);
        $collage_pic2 = imagecreatefromjpeg($collagePhoto[1]) or die("no imagcreate");
        imagecopy($my_collage, $collage_pic2, $width, 0, 0, 0, $width, $height);
        $collage_pic3 = imagecreatefromjpeg($collagePhoto[2]) or die("no imagcreate");
        imagecopy($my_collage, $collage_pic3, 0, $height, 0, 0, $width, $height);
        $collage_pic4 = imagecreatefromjpeg($collagePhoto[3]) or die("no imagcreate");
        imagecopy($my_collage, $collage_pic4, $width, $height, 0, 0, $width, $height);
        break;
    case '2x4':
        // make collage
        $degrees = -90;

        list($width, $height) = getimagesize($collagePhoto[0]);
        shell_exec(sprintf('convert %s -rotate %s %s',$collagePhoto[0],$degrees,$collagePhoto[0]));
        shell_exec(sprintf('convert %s -rotate %s %s',$collagePhoto[1],$degrees,$collagePhoto[1]));
        shell_exec(sprintf('convert %s -rotate %s %s',$collagePhoto[2],$degrees,$collagePhoto[2]));
        shell_exec(sprintf('convert %s -rotate %s %s',$collagePhoto[3],$degrees,$collagePhoto[3]));
        list($width_rotate, $height_rotate) = getimagesize($collagePhoto[0]);
        $my_collage_height = $height * 3.3;
        $my_collage_width = $width * 3.3;
        $height_offset = ((($my_collage_height/2)-$height_rotate)/2);
        $width_offset = (($my_collage_width-($width_rotate*4))/5);
        $my_collage = imagecreatetruecolor($my_collage_width,$my_collage_height) or die("Kann keinen neuen GD-Bild-Stream erzeugen");
        $background = imagecolorallocate($my_collage, 240, 240, 240);
        imagefill($my_collage,0,0,$background);
        $collage_pic1 = imagecreatefromjpeg($collagePhoto[0]) or die("no imagcreate");
        imagecopy( $my_collage, $collage_pic1,$width_offset,$height_offset,0,0,$width_rotate,$height_rotate); // Bild 1 oben
        imagecopy( $my_collage, $collage_pic1,$width_offset,($height_rotate+(3*$height_offset)),0,0,$width_rotate,$height_rotate); // Bild 1 unten
        $collage_pic2 = imagecreatefromjpeg($collagePhoto[1]) or die("no imagcreate");
        imagecopy ( $my_collage, $collage_pic2,($width_offset*2+$width_rotate),$height_offset,0,0,$width_rotate,$height_rotate); // Bild 2 oben
        imagecopy ( $my_collage, $collage_pic2,($width_offset*2+$width_rotate),($height_rotate+(3*$height_offset)),0,0,$width_rotate,$height_rotate); // Bild 2 unten
        $collage_pic3 = imagecreatefromjpeg($collagePhoto[2]) or die("no imagcreate");
        imagecopy ( $my_collage, $collage_pic3,($width_offset*3+2*$width_rotate),$height_offset,0,0,$width_rotate,$height_rotate); // Bild 3 oben
        imagecopy ( $my_collage, $collage_pic3,($width_offset*3+2*$width_rotate),($height_rotate+(3*$height_offset)),0,0,$width_rotate,$height_rotate); // Bild 3 unten
        $collage_pic4 = imagecreatefromjpeg($collagePhoto[3]) or die("no imagcreate");
        imagecopy ( $my_collage, $collage_pic4,($width_offset*4+3*$width_rotate),$height_offset,0,0,$width_rotate,$height_rotate); // Bild 4 oben
        imagecopy ( $my_collage, $collage_pic4,($width_offset*4+3*$width_rotate),($height_rotate+(3*$height_offset)),0,0,$width_rotate,$height_rotate); // Bild 4 unten
        break;
    default:
        break;
}
andi34 commented 5 years ago

convert command needs imagemagick, right?

KH404 commented 5 years ago

Yeah that's right. I tested it in the cmd and when it worked, for me it was the easiest way to make an "shell_exec". But I assume there is a way better solution xD

andi34 commented 5 years ago

Imagemagick doesn't seem to perform that well on the Pi, quite resource hungry compared with GD.

andi34 commented 5 years ago

https://www.php.net/manual/de/function.imagerotate.php should be reworked to use the GD way.

Parts to modify:

sualko commented 5 years ago

@KH404 would be nice if you could create a pr. As mentioned by @andi34 we want to use only gd at the moment and there are some other parts which needs some modifications. For example you have to take 8 pics now and not only 4.

KH404 commented 5 years ago

Unfortunately for me it is not possible to do these changes. Right now I do not have the time for, because I am going to be a father in the next few days. Maybe I will find the time when the baby won't let me sleep ;)

P.s.: There is no need to take 8 pictures.The four pictures on the left are the same then the four on the right. So if you cut it in half, both stripes are equal. One for the guest and one for e.g. the guest book.

grafik

sualko commented 5 years ago

Unfortunately for me it is not possible to do these changes.

That's ok. I thing it's a nice feature, but not urgent.

Right now I do not have the time for, because I am going to be a father in the next few days.

Congratulations :clap:

andi34 commented 4 years ago

Reopen as not applied here.

andi34 commented 2 years ago

Photobooth v4 includes the new layout https://photoboothproject.github.io/Changelog