Lionel MM
asked on
PHP Best Practice--Picture Names with ot without spaces
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-Caladiu m-Bulbs.jp g ("-" between each word)
or Blaze_1_Fancy_Leaf_Caladiu m_Bulbs.jp g ("_" 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!
Blaze-1-Fancy-Leaf-Caladiu
or Blaze_1_Fancy_Leaf_Caladiu
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I also like to do as much as I can independent of pluginsI 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
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.
If you're running Linux, just install PERL's rename utility, then run a rename.
For example, running Ubuntu...
For example, running Ubuntu...
apt-get install rename
rename 's/_/-/' *.jpg
ASKER
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.
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.
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.
ASKER
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.
ASKER