Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-07-16 13:07:40

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

[request] Image filename converter: 1.jpg => 1_imagename.jpg ???

SEO necessities seem to require today, that search engine find a proper description of an image content within the image filename already.
Or in other words i have a number of clients today, who require ME to work like this, but i can’t with the given TXP image naming system.

i am aware of this issue having been discussed for long, and it seems, that certain TXP core procedures just like to work with numbers instead of names.

Since image names are inserted automatically into the database upon upload of a new image it doesn’t sound like a major thing to save them as 1_imagename.jpg or 1t_imagename.jpg (for thumbnails) instead of 1.jpg/1t.jpg.
Who could lay out a road map how to do this? I am asking, because I am not a major expert in more complicated PHP programming myself, although i have written (very small) plugins here and there, mostly for personal use.

Thank you for any hints.


A hole turned upside down is a dome, when there’s also gravity.

Offline

#2 2011-07-16 19:40:36

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,306

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

Yup, really love to see a slick TXPish solution here.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2011-07-16 20:45:08

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

If you actually want images be saved as the way you described, then you will need to rewrite all of the code that makes Images tab — and couple of the TXP tags. Not an easy task, well more of an annoying if anything.

If no one fancies about recoding everything, then there is an option that works by using symbolic links. Every time an image is uploaded or the name is changed, symlink is generated pointing to the physical image.

That way the images can be linked the way you described with minimal drawback, and nothing needs to be re-coded as the images will be uploaded the same way they were, only difference is the symbolic link generated by a plugin. The problem you will face is that you will have to reliably know when image has been uploaded/modified and the server needs to allow/support symbolic links.

And then there is the quick way of using URL rewriting as seen here. Problem is that it won’t validate links, not without passing the requests to a server side script which then would degrade performance.

If I were the one to choose from those options, I would go with symbolic links. URL rewriting using PHP script eats too much server resources compared to static files and recoding everything isn’t optimal.

Last edited by Gocom (2011-07-16 20:55:11)

Offline

#4 2011-07-16 21:09:05

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

Apparently Hans has been asking for this for about half a decade or so. I wonder how much code is actually involved…

Offline

#5 2011-07-16 21:21:39

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

michaelkpate wrote:

I wonder how much code is actually involved…

A lot! It’s not so much the refactorisation to reference the images by name and check/resolve duplicates but how to do it such that existing sites with a zillion images don’t fall over on upgrade. Having two naming conventions running side by side is sticky, and automatically updating all existing images on upgrade is fraught with the unknown and may leave your /images dir in a real pickle if something falls over during the process.

I’d far rather this be looked at as a wider goal of spreading the load in the filesystem. Having a single dir for all images is just annoying (simple from a code perspective, yes, but far from ideal when you have 1000 of the buggers and you want to list them in your FTP program or file manager and have to wait… and wait…)

Patches always welcome :-)

Last edited by Bloke (2011-07-16 21:22:21)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#6 2011-07-16 21:25:26

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,379
Website GitHub Mastodon

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

Bloke wrote:

Patches always welcome :-)

I perused txp_image.php in the include folder. I am not ashamed to admit I couldn’t figure out what half the stuff in there does.

Offline

#7 2011-07-16 21:33:31

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

michaelkpate wrote:

I am not ashamed to admit I couldn’t figure out what half the stuff in there does.

You’re not alone. At least 42% of that file is pure voodoo to me. It. Just. Works :-)

Last edited by Bloke (2011-07-16 21:33:46)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#8 2011-07-16 22:28:17

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

Bloke wrote:

(simple from a code perspective, yes, but far from ideal when you have 1000 of the buggers and you want to list them in your FTP program or file manager and have to wait… and wait…)

You shouldn’t have to wait that long, not with such small number. For example when using SFTP (which what I imagine is what most use or should use instead of FTP) the thing changing is the size of array transferred.

File manager script written in PHP? Sure. For example upload 1000 files to Textpattern’s Files tab and see the difference. It might take a while as there is the code checking the status of the file (if it exists or not) and used for populating the list of importable items.

Last edited by Gocom (2011-07-16 22:29:47)

Offline

#9 2011-07-25 18:42:31

jayrope
Plugin Author
From: Berlin
Registered: 2006-07-06
Posts: 687
Website Mastodon

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

Gocom wrote:

[…] there is an option that works by using symbolic links. […]

That sounds intriguing. (i guess the alias should be named 1.jpg, pointing to imagename.jpg)

Still thinking the plugin option though.

Now presuming webspace is no problem:
For a start it seems possible to have a plugin
- create a second image folder first
- upon image upload create a copy of the 1.jpg file named 1-imagename.jpg from the data in txp image database, respectively 1t.jpg => 1-imagename-t.jpg
- provide a new version of <txp:image_url /> which simply simply associates a given id with the saved imagename.jpg
- if an image name gets changed later (in txp image editor), then old 1-imagename.jpg/1-imagename-t.jpg get deleted, new ones create upon pressing save button on image edit page.

Is that a roadmap?
(I’m sorry i haven’t replied earlier, i forgot to subscribe to the thread)


A hole turned upside down is a dome, when there’s also gravity.

Offline

#10 2011-07-25 19:27:12

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

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

The alias really should be imagename.jpg pointing to 1.jpg, unless you rewrite TXP core code or are prepared to handle every possible corner case.

You could limit probably yourself to using the following callback_events if you never change the name of an already uploaded file:
image_deleted
image_uploaded

Instead of using the -t suffix, you could create a separate thumbnail directory.
And instead of the fixed 1- prefix, you could add it only (as a suffix, which looks nicer) if that image name doesn’t already exist, automatically changing the image name in the database as well to match it.

Offline

#11 2011-07-25 20:45:13

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,447
Website GitHub

Re: [request] Image filename converter: 1.jpg => 1_imagename.jpg ???

I’d echo Ruud’s sentiment. A separate directory is the way I went with smd_thumbnail and it keeps things neat.

Actually, it probably wouldn’t be that hard to roll this kind of thing into my plugin since it has routines to handle image subdirs already, but renaming the image is where the problems arise and the lines of code spiral (verify characters are valid for filenames — a Txp internal function can handle this dumbing down — check file doesn’t exist, bail out if so, blah blah).

In fact, if you wanted to patch the plugin I’d take a look at it and consider rolling it in — there’s a market for this functionality, regardless I’m not convinced it makes any difference to SEO (it might, I just don’t have enough evidence to back it up). smd_thumbnail v0.22 is written, which adds a really useful url display feature so if you wanted to have a go at playing with it, drop me a line and I’ll send you the latest version.

Last edited by Bloke (2011-07-25 20:45:51)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

Board footer

Powered by FluxBB