duck7000 / imdbGraphQLPHP

5 stars 0 forks source link

Added crop/resize to thumb images #28

Closed duck7000 closed 8 months ago

duck7000 commented 9 months ago

I have added crop/resize to primary, recommendations and mainphoto images to get thumb images just like on imdb.com

The previous method i used only controlled the height of the image so keeping the original aspect ratio. In some cases this lead to distortion or an image with a smaller height then expected.

So i did final break the code parameters imdb uses to control their images to make this possible.

Full images and person images are still the same untouched

I will release a new version soon but i think that not everyone uses those images but me

Edit: I'm working on this for episode images as well, some images are also distorted.

duck7000 commented 9 months ago

Uploaded new version, it was very very hard to get even slightly right so bear me

I did understand how the images creation works but that didn't mean the implantation was easy.. that was the hard part in fact, hence a lot of changes and reverted changes

I know most of you don't use the thumbnail images but it was important to me as i use them in my program.

duck7000 commented 9 months ago

Trailer images are now finally also fixed, i added rawurlencode but that was half the work as imdb handles % signs encoded as well So normally with php rawurlencode replaces for example spaces with %20 But for imdb i had to do that twice to encode % sign as well like this %2520

duck7000 commented 9 months ago

I pushed a new version to fix encoding errors in title used for thumbnail creation

duck7000 commented 8 months ago

I need help with those cropped images, i can't seem to understand what imdb uses as criteria to determine if the image parameter starts with SX or SY. That parameter has influence on how the image is cropped, if the wrong value is used the image gets borders. The calculated crop value seems to be correct in my functions, so that works, but how to determine the X or Y value is beyond me.

Those parameters look like this: V1_QL75_SY281CR5,0,190,281. Imdb threats images differently even if those source images are almost all portrait. it is driving me nuts :)

A few source images:

972 X 1440 -> imdb treats this image as SX 838 X 1307 -> imdb treats this image as SY 1019 X 1500 -> imdb treats this image as SY 298 X 475 -> imdb treats this image as SX 355 X 355 -> imdb treats this image as SY 638 X 900 -> imdb treats this image as SY 770 X 1100 -> imdb treats this image as SY 580 X 859 -> imdb treats this image as SX

What criteria does imdb use is the big question. I tried the aspect ratio factor but that doesn't seem to be it above or below a certain width or height doesn't seem to be it either

duck7000 commented 8 months ago

i think.. i finally found how its done They compare the new aspect ratio with the source aspect ratio

so if the source is 500 x 763 $ratio_orig = 500/763 And the new image size is 190 x 281

            if (190/281 < $ratio_orig) {
                parameter = SY
            } else {
               parameter = SX
           }

I tested this with 50 different movies and in all those cases the parameter is correct and the same as what imdb uses on their site, so i sincerely hope that is finally done.

I will test/ adjust the other methods that use thumb images as well like recommendations, episodes and maybe cast although cast seems to be working like it is now

duck7000 commented 8 months ago

i uploaded the changes for the main title image so if you have the time check it out

duck7000 commented 8 months ago

I fixed the other methods to use the new private method resultParameter() and pushed a new version. cast, episode, recommendation and title image are now fixed.

It is possible to change newImageWdith and newImageHeight if you like, this is possible inside those methods. if anyone want those variables as method parameter let me know.

mainphoto remains unchained as this is working fine

duck7000 commented 8 months ago

The last issue with thumbnails.. yeah i know

I added a new method to determine if crop has to be round to previous or next even integer. In the previous methods the calculation was not 100% correct, though the difference was 1 pixel but it bothers me hah

The calculation is now correct and just like imdb on their site.

I know that most of you don't use those thumbnail images but i do so finally it is correct.

duck7000 commented 8 months ago

Closing this one as it works like it should