Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Offline
Re: Automatic thumbnails for Textpattern
etc wrote #341567:
The message can be seen in the image source. Inspecting the server response is the first thing I do in such cases.
Yeah that’s what I do when debugging, but it doesn’t help people who are less well versed in using the inspector.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
The absence of the traditional 123t.ext thumbnail for automatic type looks debatable. We can adapt the core, but plugins like com_article_image expect it to be there when thumbnail != 0 in txp_image table. At least, imagesrcurl() function probably needs to be patched.
Offline
Re: Automatic thumbnails for Textpattern
If it’s a problem, we can always make it, regardless. Or patch com_article_image to understand thumbnail = 2.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
Would it be possible to force an output format when using <txp:image_url thumbnail width="123" />?
eg. .png to .jpg or .avif
I regularly come across poor PageSpeed rankings due to the format of the original image (typically .png used for photo imagery).
Offline
Re: Automatic thumbnails for Textpattern
giz wrote #341584:
Would it be possible to force an output format when using
<txp:image_url thumbnail width="123" />?
Hmm, I can’t see that as a parameter in the docs. Under the hood it does a like-for-like downsize, retaining the original format.
In theory, once the incoming stream has been converted to an image in memory, it should be possible to divert it to a different format by overriding the default ‘use the same format’ when calling ->render(). But it’s tied internally to the mime type (because it needs to serve that) and there are function call upon call upon call that are chained together to detect those.
If I can unpick some of that, there might be a way we can wire up a parameter like /tavif/ and use that as the mime type and then it should spit out the converted image. I’ll have a play, but I’m not sure how successful it’ll be at this stage.
Last edited by Bloke (2025-12-06 18:30:14)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
Is there an option to create two alternative thumbnail resizing when uploading an image: ie. thumbnail 1 and thumbnail 2?
So that when uploading an image, say of a size 400×800, thumbnail 1 could be resized to 200×400 and thumbnail 2 to 100×200?
Would be useful to accommodate media sizes as in this example:
<source srcset="https://mysite.ca/img/portfolio/screen-1-small.png" media="(max-width: 30em)">
<source srcset="https://mysite.ca/img/portfolio/screen-1-medium.png" media="(max-width: 48em)">
<source srcset="https://mysite.ca/img/portfolio/screen-1.png">
or should one simply create the alternate sizes before uploading?
…. texted postive
Offline
Re: Automatic thumbnails for Textpattern
bici wrote #341586:
Is there an option to create two alternative thumbnail resizing when uploading an image
There’s no need. That’s the point. If you want two or more different sizes in your srcset, just put the tags there and the images will be created at whatever widths / heights you specify.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
Bloke wrote #341588:
There’s no need. That’s the point. If you want two or more different sizes in your srcset, just put the tags there and the images will be created at whatever widths / heights you specify.
prefect! … I hadn’t realized that . But I still need one thumbnail so all good!
…. texted postive
Offline
Re: Automatic thumbnails for Textpattern
bici wrote #341586:
Is there an option to create two alternative thumbnail resizing when uploading an image … or should one simply create the alternate sizes before uploading?
Bloke wrote #341588:
There’s no need. That’s the point. If you want two or more different sizes in your srcset, just put the tags there and the images will be created at whatever widths / heights you specify.
bici, with the new method, you would do something like this for your situation (using your chosen widths and img id#s):
<txp:images id="1,2,3" wraptag="picture" break="">
<source srcset="<txp:image_url thumbnail width="1600" />" media="(width >= 800px)">
<source srcset="<txp:image_url thumbnail width="1200" />" media="(width >= 600px)">
<img src="txp:image_url />" alt="txp:image_info type="alt" />">
</txp:images />
But if you wish to use the source tag expressly to art direct your images, i.e. your images are actually different at the respective sizes, you may need to go back to the old method of creating your individual sizes and uploading the other(s) as a thumbnail. If you have several, you’d still need smd_thumbnail for that.
TXP Builders – finely-crafted code, design and txp
Offline
Re: Automatic thumbnails for Textpattern
jakob wrote #341591:
bici, with the new method, you would do something like this for your situation (using your chosen widths and img id#s):
<txp:images id="1,2,3" wraptag="picture" break="">...But if you wish to use the
sourcetag expressly to art direct your images, i.e. your images are actually different at the respective sizes, you may need to go back to the old method of creating your individual sizes and uploading the other(s) as a thumbnail. If you have several, you’d still need smd_thumbnail for that.
tested and it works fine. thanks.
…. texted postive
Offline
Re: Automatic thumbnails for Textpattern
Inserting in the article body a <txp:article_image /> tag and assign an image ID in the article image field. View on the public side. Wall of text error: Fatal error: Uncaught Error: Call to undefined function imageBuild()@. Stack trace below (line breaks added for readability).
Before the recent image / thumbnail changes this worked fine.
Fatal error: Uncaught Error: Call to undefined function imageBuild() in /Users/username/Sites/phiw13-local/textpattern/publish/taghandlers.php:2110
Stack trace:
#0 [internal function]: article_image(Array, NULL)
#1 /Users/username/Sites/phiw13-local/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func('article_image', Array, NULL)
#2 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(540): Textpattern\Tag\Registry->process('article_image', Array, NULL)
#3 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(429): processTags('article_image', '', NULL, false)
#4 /Users/username/Sites/phiw13-local/textpattern/publish/taghandlers.php(1732): parse('<txp:article_im...')
#5 /Users/username/Sites/phiw13-local/textpattern/publish/taghandlers.php(1763): txp_sandbox(Array) #6 [internal function]: body(Array, NULL)
#7 /Users/username/Sites/phiw13-local/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func('body', Array, NULL)
#8 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(540): Textpattern\Tag\Registry->process('body', Array, NULL)
#9 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(429): processTags('body', '', NULL, false)
#10 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_misc.php(3735): parse('<article class=...')
#11 /Users/username/Sites/phiw13-local/textpattern/publish.php(1145): parse_form('default')
#12 /Users/username/Sites/phiw13-local/textpattern/publish.php(1173): doArticle(Array, NULL)
#13 /Users/username/Sites/phiw13-local/textpattern/publish.php(1008): parseArticles(Array, false, NULL)
#14 [internal function]: article(Array, NULL)
#15 /Users/username/Sites/phiw13-local/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func('article', Array, NULL)
#16 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(540): Textpattern\Tag\Registry->process('article', Array, NULL)
#17 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(429): processTags('article', '', NULL, false)
#18 /Users/username/Sites/phiw13-local/textpattern/publish/taghandlers.php(2256): parse('\r\n<txp:if_secti...', false)
#19 [internal function]: if_article_list(Array, '\r\n<txp:if_secti...')
#20 /Users/username/Sites/phiw13-local/textpattern/vendors/Textpattern/Tag/Registry.php(140): call_user_func('if_article_list', Array, '\r\n<txp:if_secti...')
#21 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(540): Textpattern\Tag\Registry->process('if_article_list', Array, '\r\n<txp:if_secti...')
#22 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_publish.php(429): processTags('if_article_list', '', '\r\n<txp:if_secti...', false)
#23 /Users/username/Sites/phiw13-local/textpattern/lib/txplib_misc.php(3811): parse('<txp:smd_token ...')
#24 /Users/username/Sites/phiw13-local/textpattern/publish.php(770): parse_page('archive', 'theme_25')
#25 /Users/username/Sites/phiw13-local/index.php(81): textpattern()
#26 {main} thrown in /Users/username/Sites/phiw13-local/textpattern/publish/taghandlers.php on line 2110
The form used is nearly stock forms/misc/images.txp that comes with the default install.
I tested this on local copy of a live site and a nearly vanilla install.
Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern
phiw13 on Codeberg
Offline
Re: Automatic thumbnails for Textpattern
phiw13 wrote #341605:
Uncaught Error: Call to undefined function imageBuild()@. .
That’s strange. The calls to include the admin-side library are both in place:
github.com/textpattern/textpattern/blob/dev/textpattern/publish.php#L842
github.com/textpattern/textpattern/blob/dev/textpattern/publish.php#L868
🤔🤔
Edit: Ah wait, maybe article_image needs to know about this too. I’ll check.
Last edited by Bloke (2025-12-08 11:13:17)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
Try this and see if the error goes away.
Edit: no, wait. Needs more consolidation. Bear with me while I get the code aligned with the image tag.
Thanks for the report.
Last edited by Bloke (2025-12-08 16:30:01)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline
Re: Automatic thumbnails for Textpattern
Okay, I think that’s better. <txp:article_image>, <txp:thumbnail> and <txp:image thumbnail> are now more closely in step.
If you use a valueless thumbnail it will use the most appropriate thumbnail as defined in the database. So if an image is specifed as type=“auto” (a.k.a. Type 2) then you’ll see an automatically generated thumb – assuming you specify some dimension or crop values. But if your image is type 1 (custom thumbnail) you’ll see the IDt.ext version (if it exists), scaled accoprding to the width/height attribute.
You can override this by specifying a particular thumbnail value. If you don’t specify dimensions for an auto-generated thumbnail, you’ll get the full size image. And if you specify dimensions for a full size image, it will be scaled accordingly.
Here are some examples of the various options:
<!-- Render article image(s) as full size pics -->
<txp:article_image />
<!-- Render article image(s) as full size pics, scaled to 200px wide -->
<txp:article_image width="200" />
<!-- Render article image(s) as thumbnails scaled to 200px wide.
Use custom thumbs as the source if they exist, otherwise auto-generate them -->
<txp:article_image thumbnail width="200" />
<!-- Render article image(s) as thumbnails scaled to 200px wide.
Force custom thumbs (if they've been created) and scale them -->
<txp:article_image thumbnail="1" width="200" />
<!-- Render article image(s) as thumbnails scaled to 200px wide.
Force auto-generated thumbs to be created -->
<txp:article_image thumbnail="2" width="200" />
Please play with as many article_image/image/thumbnail tags and combinations as you can think of, with and without dimensions, with width="" and/or height="" (which should still remove the width and height attributes from the resulting img tag) and see if the output matches your expectations.
Last edited by Bloke (2025-12-09 01:09:44)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Hire Txp Builders – finely-crafted code, design and Txp
Offline