completed Image crop=portrait

SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
Do we still have crop="portrait" for jrImage_display?

I can see it in the jrImage code, but it doesn't seem to do anything unless I'm approaching it wrongly.

I'm hoping it will do a "crop from the top" type of crop.

Thanks for any advice!


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 07/29/17 04:48:25AM
michael
@michael
7 years ago
7,719 posts
Not sure of the term is there or not, but the ratio will work.
crop=16:9
crop=4:3 (the best ratio for laptops that is no longer availalbe :( )
crop=16:10 (the next best thing to a 4:3 laptop monitor)
crop=1:1 (same as square)

whatever you like. :)
SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
Hi Michael

Yes, the crops work perfectly :) I use them a lot.

But they all crop from the middle of the image height. I am looking for something which would crop the top portion of a tall image and it seemed that "portrait" might do that - apparently it assumes that a person's face is in the top third of the image but I can't get it to do anything at all.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
7 years ago
7,719 posts
bugger, thought I had it with that answer. ;)

if the ratio is something like 1:16 it should be using the center of the width I would expect, because the overflow would be in that direction.

You're needing an off-set. hmmm. need to go look. back soon.
michael
@michael
7 years ago
7,719 posts
jrImage_create_image() is the function that takes that crop argument.

--

filter=?????

arguments can also be used.

--


Answer: Yes 'portrait' is an image value. and you're right, it takes the top portion:
     case 'portrait':
                // With a portrait crop, we expect the images to be of people,
                // with their head in the upper 3rd of the picture
                if ($src_width > $src_height) {
                    $diff         = ($src_width - $src_height);
                    $src_x_offset = round($diff / 2);
                    $src_width    = $src_height;
                }
                else {
                    $diff         = ($src_height - $src_width);
                    $src_y_offset = round($diff / 4);
                    $src_height   = $src_width;
                }
                $_post['height'] = $_post['width'];
                $new_height      = $new_width;
                break;
SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
Thanks Michael, portrait does indeed work, just not quite how I thought it would.

If I override the core code by adding $src_y_offset = 0; just before the // create resource section in jrImage_create_image() it crops from the top. But I can't override it there anyway :(


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 03/20/17 05:34:17PM
michael
@michael
7 years ago
7,719 posts
but if you could you'd be happy?

I'll get a ticket opened on it.
SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
I'm happy anyway man :) But thanks for thinking about it.

I was thinking that the simplest way might be to allow an offset to be passed in with the crop.

crop="width:height:x_offset:y_offset"

So crop="16:9:0:0" crops from the top left, crop="16:9:-0:-0" crops from the bottom right. I'm only really interested in cropping from the top though.


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

updated by @ultrajam: 03/20/17 07:03:15PM
michael
@michael
7 years ago
7,719 posts
thats a good way to do it.
SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
The easiest that I can see is to add this at line 1694 at the end of the // Cropping section of jrImage_create_image()
		$_offsets = explode(':', $_post['crop']);
		if (count($_offsets) == 4) {
			$src_x_offset = $_offsets[2];
			$src_y_offset = $_offsets[3];
		}
So that part of the function now looks like this:
                }
                break;
        }
		$_offsets = explode(':', $_post['crop']);
		if (count($_offsets) == 4) {
			$src_x_offset = $_offsets[2];
			$src_y_offset = $_offsets[3];
		}
    }
    else {
        // maintain aspect ratio of original image
        $new_height      = (int) (($src_height / $src_width) * $new_width);
        $_post['height'] = $new_height;
    }

    //----------------------------------
    // create resource
    //----------------------------------

Then in the jrImage_display smarty function use crop="16:9:0:0"

I don't see any notices or warnings in the error log, so I'll leave that in place and try out some different combinations of cropping.

I can manage without it by capturing multiple images per module item, but it would be very nice to have if possible :)


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)
michael
@michael
7 years ago
7,719 posts
looks good to me if you've tested it and it works. I'll add it in and see if it gets brians OK.

Thanks Steve.

--edit--
Added it in to jrImage ver 2.0.0b1
Added (int) to force to integer.
updated by @michael: 03/22/17 12:04:11AM
SteveX
SteveX
@ultrajam
7 years ago
2,584 posts
Thanks :)


--
¯\_(ツ)_/¯ Education, learning resources, TEL, AR/VR/MR, CC licensed content, panoramas, interactive narrative, sectional modules (like jrDocs), lunch at Uni of Bristol. Get in touch if you share my current interests or can suggest better :)

Tags