Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-03 19:43:38

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#2 2009-09-03 20:42:10

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

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

#3 2009-09-03 20:42:43

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

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

#4 2009-09-03 21:06:22

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#5 2009-09-03 21:09:05

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#6 2009-09-03 22:23:10

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

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


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#7 2009-09-03 22:37:56

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#8 2009-09-03 23:06:13

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: soo_thumb_atts: update thumbnail data after the Txp 4.2.0 upgrade

I haven’t tried it, but that should work. Some room for improvement:
  • you’re selecting thumbnail, thumb_h, thumb_w columns in your SQL query, but because the WHERE part says thumbnail = 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

#9 2009-09-04 01:43:09

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#10 2009-09-04 06:38:51

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#11 2009-09-04 14:23:35

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

Board footer

Powered by FluxBB