Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
As discussed in this thread, here is a plugin that automatically adds in height and width values for thumbnails that were already in place when you upgraded to Txp 4.2.0.
Caveat: to do this, naturally the plugin must update records in your Txp database. I have tested it several times on one installation, but to be safe you should back up your database before proceeding with this.
Get it here: http://ipsedixit.net/txp/91/soo_thumb_atts
Last edited by jsoo (2009-09-03 19:48:08)
Code is topiary
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
Useful plugin! I’ve had a look at the source code. I hope you don’t mind me commenting.
Assuming getimagesize() is an expensive function, this plugin probably won’t work if you have a lot of images, because you’ll run into a PHP timeout settings (if set, and they often are). This is why the devs aren’t doing this as part of the upgrade scripts. If this plugin is intended for filling the missing thumb height/weight in the images table, then I’d recommend:- operate only on images actually have a thumbnail, but have height/weight set to 0 in txp_images… assuming that’s the default value for the ‘old’ images.
- use a single loop that does both getimagesize() and the update of the corresponding thumb dimensions in the database.
- instead of fetching all columns (‘*’) in txp_image, fetch only the ones that you actually use (‘id’)… and use a clever query. Don’t fetch records that you don’t need if you can exclude them in the SQL query (which is basically what I meant in my first recommendation). This saves memory and increases speed as well, which in turn reduces the chance of actually running into a timeout problem.
- and of course, if you have a lot of images, first showing what will be changed before updating will not work (timeout!).
The first, second and fourth recommendations will make it possible to run the plugin multiple times in a row, allowing it to restart at the first image that doesn’t have thumb dimensions set. If you wanted to reset all thumb dimensions (even the ones that were somehow set incorrectly to non-zero values), you may want to first set them all to zero (in a single update query) and then set them again to the correct dimensions.
Final nitpick: can you offer the plugin for download directly as a .txt file instead of a .zip?
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
Thank you very much for this one Jeff. I can see that it will save us much time, effort and possibly grief as we go about upgrading some image heavy sites to TXP 4.0.2.
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
ruud wrote:
can you offer the plugin for download directly as a .txt file instead of a .zip?
Here is the direct download. This will sound kind of stupid, but the reason I got in the habit of packaging plugins this way is how Txp handles file content. The file name is not editable, meaning otherwise one has to make a new file entry on uploading a new version.
Edit: current download link.
Last edited by jsoo (2009-09-29 22:44:37)
Code is topiary
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
ruud wrote:
Useful plugin! I’ve had a look at the source code. I hope you don’t mind me commenting.
Quite the contrary — thanks very much for the suggestions. I will ponder coming up with a more efficient query, etc.
Code is topiary
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
jsoo wrote:
…the reason I got in the habit of packaging plugins this way is how Txp handles file content. The file name is not editable, meaning otherwise one has to make a new file entry on uploading a new version.
Check out rah_plugin_download
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
MattD wrote:
Check out rah_plugin_download
Thanks Matt — checking it out now.
Just uploaded version 0.2, although the direct link still has the old file name until I figure out what to do with rah_plugin_download…
Version 0.2 incorporates Ruud’s suggestions (I think).
Edit: current download link
Last edited by jsoo (2009-09-29 22:45:24)
Code is topiary
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
- you’re selecting
thumbnail, thumb_h, thumb_w
columns in your SQL query, but because the WHERE part saysthumbnail = 1 and thumb_h = 0 and thumb_w = 0
you already know their values, so there’s no need to fetch them from the database. - for that same reason, the condition
$width != $thumb_w or $height != $thumb_h
is always true, because no thumbnail image has dimensions 0×0, so you can remove it. - and if the thumbnail image file doesn’t exist… perhaps you can set
thumbnail=0
for that image in txp_image? Might be outside the scope of the plugin. I don’t know.
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
ruud wrote:
perhaps you can set
thumbnail=0
for that image in txp_image? Might be outside the scope of the plugin. I don’t know.
I think it is outside the scope of this one, though the scope could easily be expanded to a general-purpose txp_image integrity check. But not for now, because the plugin is only looking at images with thumbnail h/w set to 0; I wouldn’t want to check for missing files unless I were to check all images.
Thanks again for all your help. Version 0.2.1 takes your suggestions for code cleaning. Also, I’ve gotten started with rah_plugin_download, hence:
Version 0.2.1 current version
Last edited by jsoo (2009-09-29 22:46:10)
Code is topiary
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
Maybe it’s too cool, but for users with plenty of images would be nice to see console output with showing how many images where updated and how many is elapsed – ajax technology would be great :)
Very useful plugin, thanks!
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade
the_ghost wrote:
Maybe it’s too cool, but for users with plenty of images would be nice to see console output with showing how many images where updated and how many is elapsed – ajax technology would be great :)
That would be a nice enhancement. Sadly my AJAX skills aren’t up to the task. Actually, they are nonexistent :)
Code is topiary
Offline