codefog / contao-social_images

Enable the images on your website for the social portals like Facebook or Google+
MIT License
9 stars 2 forks source link

Contao 4.8 - not all possible og:image are generated #27

Closed berecont closed 4 years ago

berecont commented 4 years ago

Contao 4.8.4 codefog/contao-social_images 3.5.5 There is only the default image generated, choosen in site structure. If you don't choose one, there's no og:image generated. Other images are not collected and generated as og:image in the extension is activated in page layout.

this is both in a regular page an in the news page

qzminski commented 4 years ago

How do you exactly add those images? For example, the image will not be considered if it is placed directly in the text editor (tinyMCE).

berecont commented 4 years ago

no, not in the text editor ... e.g. by mod_newslist or inside the mod_newsreader with galleries or single images (included by CE Image)

qzminski commented 4 years ago

@fritzmg have you got a running system on that Contao version somewhere? πŸ˜‡

fritzmg commented 4 years ago

I made a quick test in Contao 4.8 and I cannot confirm the problem. I inserted a ce_text with image and its image was inserted as an og:image in the <head>.

qzminski commented 4 years ago

Thank you very much @fritzmg for checking this one! 🍻

@berecont have you got this system online and would you be able to provide me some access details for debugging?

berecont commented 4 years ago

https://wiewarsdort.at/ and you got email ...

fritzmg commented 4 years ago

https://wiewarsdort.at/

og:image is present there. Which settings are you using?

berecont commented 4 years ago

"... There is only the default image generated, choosen in site structure...." for example: https://wiewarsdort.at/info/unterwegs-im-taffatal-horn-01-11-2019.html there should be ALL gallery images generated, but it didn't

fritzmg commented 4 years ago

Which settings are you using?

berecont commented 4 years ago
fritzmg commented 4 years ago

@qzminski while testing a gallery I indeed noticed an incompatibility with Contao 4.8:

ErrorException:
Warning: getimagesize(...\www\c48dev/assets/images/d/Deat_to_Stock_Goods_5-f9d29036.jpg): failed to open stream: No such file or directory

  at vendor/codefog/contao-social_images/classes/SocialImages.php:62
  at SocialImages\SocialImages->addSocialImages(object(PageModel), object(LayoutModel), object(PageRegular))
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:191)
  at Contao\PageRegular->prepare(object(PageModel))
     (vendor/contao/core-bundle/src/Resources/contao/pages/PageRegular.php:48)
  at Contao\PageRegular->getResponse(object(PageModel), true)
     (vendor/contao/core-bundle/src/Resources/contao/controllers/FrontendIndex.php:343)
  at Contao\FrontendIndex->renderPage(object(PageModel))
     (vendor/symfony/http-kernel/HttpKernel.php:151)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:68)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:198)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (web/index.php:31)
  at require('...\\www\\c48dev\\web\\index.php')
     (web/app.php:4)

Since Contao 4.8 we have deferred image resizing - however the social images extension wants to check the actual size of the image, before adding it as an og:image. At that time the image does not exist yet though.

@ausi can the target image size be retrieved somehow via a service?

qzminski commented 4 years ago

Hey @ausi what would be the best option here: read maximum dimensions from corresponding JSON file, or somehow force to generate the image at a runtime?

fritzmg commented 4 years ago

or somehow force to generate the image at a runtime?

This would effectively negate the advantage of the deferred image resizing process of Contao 4.8+ whenever the social images extension is installed, since it will process the images of each image, text and gallery content element on each request.

qzminski commented 4 years ago

@fritzmg that is true but I don't really see any other option as we have to know the real image size at the time page is being generated. If the image is deferred and does not exist, we'd either have to generate it or use the maximum image size set in the corresponding JSON file… that may be actually the best solution although it does not solve the problem in 100% as a small image wouldn't be upscaled and could be included despite the dimension limits.

ausi commented 4 years ago

You can replace https://github.com/codefog/contao-social_images/blob/8a7078a164acc5d007dd8b3807877f547ffaf6e2/classes/SocialImages.php#L46 and https://github.com/codefog/contao-social_images/blob/8a7078a164acc5d007dd8b3807877f547ffaf6e2/classes/SocialImages.php#L62 with the following code:

list($width, $height) = (new \Contao\File($strImage))->imageSize;

This works with both, deferred and already resized images.

qzminski commented 4 years ago

Thanks a lot @ausi 🍻

berecont commented 4 years ago

sorry @qzminski , but after updating the package there's the same issue as before. the update run with Contao Manager - 3.5.5 -> 3.5.6

fritzmg commented 4 years ago

@qzminski you forgot line 62 in SocialImages.php :)

berecont commented 4 years ago

but that isn't the solution (?) I changed line 62 and the same issue as before

fritzmg commented 4 years ago

dev-hotfix/3.5.7 fixes my issue.

I otherwise cannot reproduce the issue of @berecont . I have added a text element with image plus a gallery on one page and got the following output in <head>:

<meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%282%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1279"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_1.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_10.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_2.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_3.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1279"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_4.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/assets/images/d/Deat_to_Stock_Goods_5-f9d29036.jpg">
<meta property="og:image:width" content="1024">
<meta property="og:image:height" content="1536"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_6.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_7.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_8.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Deat_to_Stock_Goods_9.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%281%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%2810%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%283%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%284%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%285%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1371"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%286%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%287%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1279"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%288%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280"><meta property="og:image" content="http://c48.local/files/dts/Death_to_stock_photography_weekend_work%20%289%20of%2010%29.jpg">
<meta property="og:image:width" content="1920">
<meta property="og:image:height" content="1280">

The first og:image is from the text content element, the rest of the images are from the gallery content element.

qzminski commented 4 years ago

@berecont I have found the problem. You are inserting the news reader module as an insert tag which is generated after the og:image tags have been collected and added to the page. Try inserting the module as content element or directly as frontend module in page layout settings.

berecont commented 4 years ago

wow - ok, that's a problem I didn't know ... I insert the module as a content element and all works right now. thanks a lot!

fritzmg commented 4 years ago

@qzminski will you release 3.5.7 soon? We actually use the extension in 2 live Contao 4.8 installations and the problem I discovered might occur there too.

qzminski commented 4 years ago

Just released πŸ˜‰