Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-01-06 23:31:08

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 238
Website

Keywords in image file names

Has anyone thought about this issue? For SEO it’s desirable to have a keyword or two in a image file name, but currently Textpattern uses a simple running number for uploaded images.

Here is an addition to .htaccess file used in Textpattern’s root that makes it possible to put custom keywords (with latin alphabet) to existing image file names without “physically” altering the file name. This assumes images are inside images folder.

RewriteRule ^([0-9a-z-]+)-([0-9]+).(apng|png|gif|webp|avif|jpg|jpeg|jfif|pjpeg|svg|bmp|tif|tiff)$ ./images/$2.$3?slug=$1 [L]

Key points:

  • $2 = running number
  • $3 = file extension
  • $1 = keywords

An example:

images/1.png would become tomato-1.png and/or cabbage-1.png

Maybe someone finds this idea interesting and develops it further. ;-) For example a dedicated input field in Textpattern’s Edit image page could added, which would then store the keyword(s) to a database table.

Offline

#2 2023-01-07 00:09:05

bici
Member
From: vancouver
Registered: 2004-02-24
Posts: 2,091
Website Mastodon

Re: Keywords in image file names

I am in awe of what you are able to do in .htaccess

So to clarify. I upload an image called cat_on_bike.png. It goes into the TxP DB as 45.png , But your .htaccess rule renders it to indexing robots as the name i used when it was uploaded. Cool


…. texted postive

Offline

#3 2023-01-07 02:26:30

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,189
Website

Re: Keywords in image file names

  1. you can already add custom fields to the image edit panel with one of Jakob‘s extensions, jcr_image_custom
  2. as you know you can alter the file name for an image on the same panel
  3. (thinking out loud, absolutely untested) you could then build a shortcode to combine the fields above to insert in your articles, and then have some redirect in your htaccess to the id.ext on the file system.

example: the shortcode would output <img src=/images/keyword-filename-id.jpg alt=this-or-that> in your HTML, and you then redirect to /images/id.jpg


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#4 2023-01-07 06:49:09

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Keywords in image file names

It’s working fine on my local MAMP server (PC) with a little amendment:

<IfModule mod_rewrite.c>
    RewriteEngine On

	RewriteRule ^([0-9a-z-]+)-([0-9]+).(apng|png|gif|webp|avif|jpg|jpeg|jfif|pjpeg|svg|bmp|tif|tiff)$ $2.$3 [L]

</IfModule>

Note because the rule is located into the /images folder we don’t need to specify it.

Now, the image tag can be used as this:

<txp:site_url />images/<txp:image_info type="name" />-<txp:image_info type="id" /><txp:image_info type="ext" />

And https://mydomain.tdl/images/my-image-name-ID.ext is rendering from the front-end part. 👌

Last edited by Pat64 (2023-01-07 06:52:40)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#5 2023-01-07 18:12:31

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,726
Website

Re: Keywords in image file names

Hehe, here’s a thread from 2011 on the same topic using the same basic approach (hat tip to Julián and Jukka).


TXP Builders – finely-crafted code, design and txp

Online

#6 2023-01-08 14:24:10

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Keywords in image file names

This solves all cases with or without file name, even with its extension or display the current format (ID) if blank:

<img loading="lazy" itemprop="url contentUrl" src="<txp:site_url />images/<txp:evaluate query test='<txp:image_info type="name" />'><txp:image_info type="name" trim="/(.*[^\.])(\.)(.*)?/" replace='$1' />-<txp:else /></txp:evaluate><txp:image_info type="id" /><txp:image_info type="ext" />" alt="-">

Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#7 2023-02-22 15:33:21

lindabb
Member
Registered: 2023-02-17
Posts: 132

Re: Keywords in image file names

Hi,
Is there a way to upload image file with same file name without any change ?

Thanks

Offline

#8 2023-02-22 15:50:11

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

Re: Keywords in image file names

Sadly not. We are (presently) hamstrung by the legacy decision to alter the original image filename and convert it to an ID.

That does have advantages for concurrency (no collisions in multi-user environments) and limiting problems with filename clashes if you upload the same image name for more than one different image. But equally it has downsides: if you do want to replace an image you need to find it first and replace it via the UI, plus the (minor) SEO filename hit – which can be mitigated with good alt/caption text.

There’s also the issue that if you have large image collections, they’re all stored in the same directory. That makes things slow over legacy protocols like FTP, and can in extreme cases cause filesystems to slow down or run out of inodes. I’ve been experimenting with techniques to move away from this to a better, more distributed, file system but have yet to decide on the best way forward.


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

#9 2023-12-28 12:39:39

Kjeld
Member
From: Tokyo, Japan
Registered: 2005-02-05
Posts: 453
Website

Re: Keywords in image file names

Bloke wrote #334710:

Sadly not. We are (presently) hamstrung by the legacy decision to alter the original image filename and convert it to an ID.

That does have advantages for concurrency (no collisions in multi-user environments) and limiting problems with filename clashes if you upload the same image name for more than one different image. But equally it has downsides: if you do want to replace an image you need to find it first and replace it via the UI, plus the (minor) SEO filename hit – which can be mitigated with good alt/caption text.

There’s also the issue that if you have large image collections, they’re all stored in the same directory. That makes things slow over legacy protocols like FTP, and can in extreme cases cause filesystems to slow down or run out of inodes. I’ve been experimenting with techniques to move away from this to a better, more distributed, file system but have yet to decide on the best way forward.

Just discovered this thread now. As I work with many thousands of images, and require better SEO for those images, I would be extremely happy about a move to named images and having the images distributed in subfolders.


Old Photos of Japan – Japan in the 1850s~1960s (100% txp)
MeijiShowa – Stock photos of Japan in the 1850s~1960s (100% txp)
JapaneseStreets.com – Japanese street fashion (mostly txp)

Offline

Board footer

Powered by FluxBB