Ecommerce software home
Shopping Cart Software Forum for Ecommerce Templates
 
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

Find us on Facebook Follow us on Twitter View our YouTube channel
Search our site
 All Forums
 Technical
 ASP (Windows server) versions
 Alternate Text on Images in DB
Author « Topic »  

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 06/25/2024 :  06:46:34  
Hi - May i check to see if there is a way to supply the alternate text for images via the DB rather than taken from the product name? As I current understand it, the alternate text for ADA is pulled from the product name but isn't necessarily an accurate description of whats pictured in the image. So alternate image text might go 125 characters. For instance this image : https://www.google.com/url?sa=i&url=https%3A%2F%2Fwww.istockphoto.com%2Fphotos%2Fcat-yarn&psig=AOvVaw3VTGLO-wOT8VxaUt5RZXlv&ust=1719409448723000&source=images&cd=vfe&opi=89978449&ved=0CBEQjRxqFwoTCODIn73x9oYDFQAAAAAdAAAAABAE

Might read something like: "A black and white kitten with wide eyes stands on its hind legs, holding a large blue ball of yarn with one paw."

Thanks

Joe

Vince
Administrator

42685 Posts

Posted - 06/25/2024 :  08:24:28  
Hi Joe
I get what you are saying but the only way to set the ALT image text is via the product name. Really, 99% of the time this is going to reflect what is in the image so given that it's also automatic, there doesn't seem to be a great need to change the system.

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 06/25/2024 :  16:50:48  
Vince,
Thank you for your reply. I'm sure you all have a lots of priorities. Appreciate you.
Joe

dbdave
ECT Moderator

USA
10379 Posts

Posted - 06/25/2024 :  20:23:20  
Hi Joe, I think I can come up with a way for you to use one of the custom fields to enter your custom alt text, then use javascript on the front end of the site to replace the alt text attribute to what you have entered in the admin.
However, it's going to be too complicated to do that with multiple images, unless you are ok with all of the images for that product having the same alt text attribute.

Thanks,
David

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 06/26/2024 :  07:41:03  
Hello and Thanks Dave,
i have been thinking about it too but not sure how important it is for me. I thought about modifying the extending the database schema and adjusting the sql call in incproddetail.asp
---------
sSQL="SELECT "&IIfVs(mysqlserver<>TRUE,"TOP 1 ")&"imageSrc FROM productimages WHERE imageType=0 AND imageProduct='"&escape_string(prodid)&"' ORDER BY imageNumber"&IIfVs(mysqlserver=TRUE," LIMIT 0,1")
rs2.Open sSQL,cnn,0,1
if NOT rs2.EOF then psmallimage=rs2("imageSrc")
rs2.close
-------------
for instance
and something like on the asp side:
<img src="<%= rs2("imageSrc") %>" alt="<%= Server.HTMLEncode(rs2("imageAltText")) %>">
....
Seems like a good way to break my site though.



Joe

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 06/26/2024 :  07:55:46  
If i did this - I would probably not modify existing tables and just create new table with image name as key:

CREATE TABLE productImageAltText (
imageName VARCHAR(255) PRIMARY KEY,
altText TEXT
);

then join them to call:

SELECT pi.imageSrc, COALESCE(piat.altText, 'Image of ' + p.pName) AS imageAltText
FROM productimages pi
LEFT JOIN productImageAltText piat ON pi.imageSrc = piat.imageName
LEFT JOIN products p ON pi.imageProduct = p.pID
WHERE pi.imageType = 0 AND pi.imageProduct = '...'

then include the alt text in asp:

sSQL = "SELECT pi.imageSrc, COALESCE(piat.altText, 'Image of ' + p.pName) AS imageAltText " & _
"FROM productimages pi " & _
"LEFT JOIN productImageAltText piat ON pi.imageSrc = piat.imageName " & _
"LEFT JOIN products p ON pi.imageProduct = p.pID " & _
"WHERE pi.imageType = 0 AND pi.imageProduct = '" & escape_string(prodid) & "' " & _
"ORDER BY pi.imageNumber" & IIfVs(mysqlserver=TRUE," LIMIT 0,1")

rs2.Open sSQL,cnn,0,1
if NOT rs2.EOF then
psmallimage = rs2("imageSrc")
psmallimagealt = rs2("imageAltText")
end if
rs2.close

I probably would not modify form entry and instead update the table programmatically some way - but here again - not sure how important it is. It is important from an ADA perspective and also from an SEO perspective. Throw it on the pile...





Joe

dbdave
ECT Moderator

USA
10379 Posts

Posted - 06/26/2024 :  08:53:14  
I always try to figure out ways to do these type things without modifying the core files.
You would need an additional database column, but those already exist. There are three, and you can add more, so no issue there.
This would also make it easy for you to populate your alt text right in the admin.

From there, you could edit the core files, or, better, it would be quite easy to replace the alt text, when the custom field exists, using javascript right in your proddetail.asp.

David

Edited by - dbdave on 06/26/2024 08:55:46

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 06/26/2024 :  18:08:22  
I did not think about javascript. You know much more about this than me - in trying to think of a way to not use the database - you could perhaps use the product name and some portion of description if you wanted - something like

dim altText
altText = "Image of " & rs(getlangid("pName",1)) & ": " & left(rs(getlangid("pDescription",2)), 100) & "..."
print "<img" & IIfVs(NOT noschemamarkup," itemprop=""url""") & " id=""prodimage"&Count&""" class=""detailimage allprodimages"" src=""" & allimages(0,0) & """ alt="""&replace(strip_tags2(altText),"""",""")&""">"

and play some type of loop for products with multiple images

Joe

Dermontti
Advanced Member

USA
161 Posts

Posted - 07/30/2024 :  05:35:28  
We use pName - pShortDesc for a lot of things like meta page title.

I think the easiest way to do this is to add new columns to products table as nvarchar(max) or something and put all or part of the alt there, then just loop through that when using the small/reg/giant images.

You can just use incprods and add the logic to be editable in admin.

Vince
Administrator

42685 Posts

Posted - 07/31/2024 :  11:52:11  
quote:
I think the easiest way to do this is to add new columns to products table as nvarchar(max)
Not being picky or anything but if you're not using wide character sets it would be better with VARCHAR instead of NVARCHAR and unless you really want that many characters then limit to at most VARCHAR(8000) as anything above that is held as a BLOB type data type and can be difficult to handle.

Vince

Click Here for Shopping Cart Software
Click Here to sign up for our newsletter
Click Here for the latest updater

joetuesday
Advanced Member

183 Posts

Pre-sales questions only
(More Details...)

Posted - 07/31/2024 :  15:34:11  
What about adding a field to the productimages table called something like "altImageText" so you can define it image by image and then modify the sql query in incproductdetail.asp - something like retrieve alt image from field and if it isnt there then show product name:

-----------------
' Small image (main product image)
sSQL="SELECT "&IIfVs(mysqlserver<>TRUE,"TOP 1 ")&"imageSrc, altImageText FROM productimages WHERE imageType=0 AND imageProduct='"&escape_string(prodid)&"' ORDER BY imageNumber"&IIfVs(mysqlserver=TRUE," LIMIT 0,1")
rs2.Open sSQL,cnn,0,1
if NOT rs2.EOF then
psmallimage = rs2("imageSrc")
psmallimagealt = IIf(rs2("altImageText") & "" <> "", rs2("altImageText"), replace(strip_tags2(rs(getlangid("pName",1))),"""","""))
end if
rs2.close

' All regular images
sSQL="SELECT imageSrc, altImageText FROM productimages WHERE imageType=1 AND imageProduct='"&escape_string(prodid)&"' ORDER BY imageNumber"
rs2.Open sSQL,cnn,0,1
if NOT rs2.EOF then
allimages = rs2.getrows()
numallimages = UBOUND(allimages,2)+1
else
allimages = null
numallimages = 0
end if
rs2.close

' All giant images
sSQL="SELECT imageSrc, altImageText FROM productimages WHERE imageType=2 AND imageProduct='"&escape_string(prodid)&"' ORDER BY imageNumber"
rs2.Open sSQL,cnn,0,1
if NOT rs2.EOF then
allgiantimages = rs2.getrows()
numallgiantimages = UBOUND(allgiantimages,2)+1
else
allgiantimages = null
numallgiantimages = 0
end if
rs2.close

' Prepare JavaScript array for image switching
if isarray(allgiantimages) then
print "<script>"
print "pIX[999]=0;pIM[999]=["
for index=0 to numallgiantimages-1
alt_text = IIf(allgiantimages(1,index) & "" <> "", allgiantimages(1,index), replace(strip_tags2(rs(getlangid("pName",1))),"""","""))
print IIfVs(index>0,",") & "{'src':'" & encodeimage(allgiantimages(0,index)) & "','alt':'" & Server.JSEncode(alt_text) & "'}"
next
print "];"
print "</script>"
end if
--------------------------
and thenshowdetailimages() something like:
-------------------------
sub showdetailimages()
if isarray(allimages) then
if magictoolbox<>"" AND (isarray(allgiantimages) OR lcase(magictoolbox)="magic360") then
' ... (existing magic toolbox code)

for index=0 to UBOUND(allimages,2)
if UBOUND(allgiantimages,2)>=index then
alt_text = Server.HTMLEncode(IIf(allimages(1,index) & "" <> "", allimages(1,index), replace(strip_tags2(rs(getlangid("pName",1))),"""",""")))
print "<img" & IIfVs(NOT noschemamarkup," itemprop=""url""") & " src=""" & allimages(0,index) & """ alt=""" & alt_text & """"&IIfVs(giantimage<>"" AND magictoolbox="MagicSlideshow"," data-fullscreen-image="""&giantimage&"""")&">"
end if
next

' ... (rest of existing magic toolbox code)
else
alt_text = Server.HTMLEncode(IIf(allimages(1,0) & "" <> "", allimages(1,0), replace(strip_tags2(rs(getlangid("pName",1))),"""",""")))
print "<img" & IIfVs(NOT noschemamarkup," itemprop=""url""") & " id=""prodimage"&Count&""" class=""detailimage allprodimages"" src=""" & allimages(0,0) & """ alt=""" & alt_text & """>"

' ... (rest of existing non-magic toolbox code)
end if
elseif psmallimage<>"" then
print "<img" & IIfVs(NOT noschemamarkup," itemprop=""url""") & " id=""prodimage"&Count&""" class=""detailimage allprodimages"" src=""" & psmallimage & """ alt=""" & Server.HTMLEncode(psmallimagealt) & """>"
elseif defaultproductimage<>"" OR defaultdetailimage<>"" then
print "<img" & IIfVs(NOT noschemamarkup," itemprop=""url""") & " id=""prodimage"&Count&""" class=""detailimage allprodimages"" src=""" & IIfVr(defaultdetailimage<>"",defaultdetailimage,defaultproductimage) & """ alt=""Default Product Image"">"
else
print " "
end if
end sub
---------------------------

Joe

Dermontti
Advanced Member

USA
161 Posts

Posted - 08/01/2024 :  08:39:25  
Thanks Vince.

I am aware to keep the bit size down, but I inherited the database like that from previous devs and don't want to drop and reform the table.
  « Topic »  
Jump To:
Shopping Cart Software Forum for Ecommerce Templates © 2002-2022 ecommercetemplates.com
This page was generated in 0.03 seconds. Snitz Forums 2000