PHP Best Practice--Picture Names with ot without spaces

Lionel MM
Lionel MM used Ask the Experts™
on
I am using WordPress and woocommerce which using PHP on a shared server (hosted server). I have a ton of pictures I am working on, to make the names more descriptive and to add SEO IPTC info to each picture. My question is primarily about PHP best practices when it comes to names--to use with or without spaces. Example?
Blaze-1-Fancy-Leaf-Caladium-Bulbs.jpg ("-" between each word)
or Blaze_1_Fancy_Leaf_Caladium_Bulbs.jpg ("_" between each word)
or simply Blaze 1 Fancy Leaf Caladium Bulbs.jpg  (" " between each word)

Then secondarily and much less important any recommendations for apps to mass rename pictures, adding SEO IPTC info and adding watermarks to pictures?

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
I would go with dashes, but also not rely on that one piece for seo.  A long time ago Matt Cutts wrote about google using dashes for separating words and underscore for combining. I don't know if that is still true or not. As a hint, look at the url of your question here https://www.experts-exchange.com/questions/29161563/PHP-Best-Practice-Picture-Names-with-ot-without-spaces.html with dashes.

There are wordpress plug ins for this. I also use Photoshop and it has the capability. However, I find it easier to just write code to change names in mass.   Same goes for watermarks. I would bet there are plug ins for wordpress. Again, photoshop, Adobe Acrobat can do this but so can code. I use imagemagick  https://imagemagick.org at the command line for this purpose.
Lionel MMSmall Business IT Consultant

Author

Commented:
Thanks Scott--that is how my current pictures are named with dashes but wanted to make sure I was remembering right. I am also using Yoast for SEO on my site but I also like to do as much as I can independent of plugins so I have some underlying knowledge and not develop an over-reliance on one plugin for anything. I use http://www.den4b.com/products/renamer for mass renaming--easy to use and see results of name change rules added before proceeding. Photoshop is great but don't have license for it. used imagemagick in the past to add black borders to all my pictures--forgot about it so thanks for the reminder. Thanks for the other suggestions too--much appreciated.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
I also like to do as much as I can independent of plugins
I used to be that way. I was reminded too many times that I like to do things the hard way though :)

Otherwise, I agree with you. Where possible, I would rather have my own code that I feel comfortable with and reuse as needed. However, I have also found I started using carefully chosen plug ins too.  

If you are using windows, vbs is very easy to write
dim fs, folder
folder = "c:\inetub\www\images\"
old_file = "Blaze_1_Fancy_Leaf_Caladium-Bulbs.jpg"
new_file = replace(old_file, "_","-")
set fs=Server.CreateObject("Scripting.FileSystemObject")
fs.MoveFile folder&old_file, folder&new_file
set fs=nothing

Open in new window

Add some code to delete or move the originals and crate an automatic task schedule to run the vbs file or create a bat file. Many options. You can also incorporate imagemagick into this as well.  If you wanted to get fancy if you are using this for WP, then create a hook for fileuploads https://developer.wordpress.org/reference/hooks/wp_handle_upload/ where you look for an image being uploaded and adjust the file name. You can either call vbs from php or do the same type of replacement using php.  If it is wordpress, this may be a good option.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

David FavorFractional CTO
Distinguished Expert 2018

Commented:
If you're running Linux, just install PERL's rename utility, then run a rename.

For example, running Ubuntu...

apt-get install rename

rename 's/_/-/' *.jpg

Open in new window

Lionel MMSmall Business IT Consultant

Author

Commented:
after re looking at imagemajick I then looked at several different photo apps (lightroom, xnview, infranview, and others) and now find myself down the rabbit hole so I am returning here to get your recommendations as to which one to focus on, keeping in mind my main goal is to add IPTC and EXIF metadata--that is the main goal so what is the quickest and easiest way to do this, what to  focus on or which solution? Thanks! I did find uMark in my rabbit hole searching to add a simple text watermark. thank you.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
This kind of changes things from your original question.  

For updating meta data, imagemagick can take care of that https://www.imagemagick.org/discourse-server/viewtopic.php?t=29532. If you search, you will also find some GUI tools that do the same. It is just a matter of how you want to handle these.  If it is an ongoing thing and you want it automated, then imagemagick will be a good choice.  If it is a one time thing or even just a few times a year, you may find it easier tojust use a GUI rather than scripting.  

The same will go for watermarks.  You can do that with imagemagick as well or just the GD library https://www.php.net/manual/en/image.examples-watermark.php or a GUI program like photoshop, gimp or other photo editing tools.
Lionel MMSmall Business IT Consultant

Author

Commented:
thank you for the help--just to remind you of my original question--I had asked about both naming convention and "Then secondarily and much less important any recommendations for apps to mass rename pictures, adding SEO IPTC info and adding watermarks to pictures?" Since the first question was so easy to answer and basically confirmed what I thought I don't think I was out of bounds to ask for more details on the second part of my question. Regardless-thanks for your time and advise. I ended up using InfranView, uMark, XnView and Windows File Explorer to get IPTC info, resize image and add a watermark.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial