0

I have a bit of a problem, my client has decided to rebrand his website, through which 1000's of listings in Mosets have a default image (which is added to the listing through a chronoform) which shows the old branding. These images are all saved with a different file name in media/com_mtree/images So i'm at a loss as to the best way to update all of these images.

Is it possible to assign a default image to replace these all at once, or will I need to go through 1000's of listings and manually update these images? They are all around the same file size, so is there a program where by I can feed in a load of images and then get them overwritten with a copy of the new version, thus I would not have to do this manually?

Regards D

  • I'm sure there's a reason but why would you want an identical image but a different name throughout your site? Or have I misunderstood. – Eoin Jan 5 at 19:28
0

OK I have written two bash scripts. The first one creates directory of images as well as a "default" image. (Note I used imagemagick to create the default old and new images, so this might have to be installed first). The second one does all the work to replace the old default file with a new one.

script create_test_images.sh

!/bin/bash

#

20180208 R.Morgan created -- see problem Mosets Tree - Change default image for 1000's listings

# #

Requires ImageMagick

# #

Default file extension

FILEEXT=jpg #

Default file prefix for product files

FILEPREFIX=f_ # #

Subdirectory (from this script) to place the image files

SUBDIR=./media/com_mtree/images #

set the height and width of default (old and new) images

IMAGEWIDTH=640 IMAGEHEIGHT=250 # #

names of old and new default files

FILEDEFAULTORIG=default.${FILEEXT} FILEDEFAULTNEW=default_new.${FILEEXT} #

use imagemagick to create "default"

convert -size ${IMAGEWIDTH}x${IMAGEHEIGHT} -background white -fill #ed303c -gravity East label:"Default" -quality 100 ${FILEDEFAULTORIG} convert -size ${IMAGEWIDTH}x${IMAGEHEIGHT} -background yellow -fill #ed303c -gravity East label:"Default-NEW!" -quality 100 ${FILEDEFAULTNEW} # file ${FILEDEFAULTORIG} file ${FILEDEFAULTNEW} # md5sum ${FILEDEFAULTORIG} md5sum ${FILEDEFAULTNEW} #

now create selection of default files with random file names

# #

create our images subdirectory if it is not present

if [ ! -d "${SUBDIR}" ]; then mkdir -p "${SUBDIR}" fi # #

create 10000 "default" files

NUMBERDEFAULT=10000 for ((n=0;n

create 100 "random" files

NUMBERRANDOM=100 for ((n=0;n

Script replace_defaults.sh

!/bin/bash

#

20180208 R.Morgan created -- see problem Mosets Tree - Change default image for 1000's listings

# #

This second file -- the one that replaces old default files with a new one

# # # # # # #

The first file required ImageMagick

# #

Default file extension

FILEEXT=jpg #

Default file prefix for product files

FILEPREFIX=f_ #

Backup extension

BACKUPEXT=bak #

Subdirectory (from this script) to place the image files

SUBDIR=./media/com_mtree/images #

set the height and width of default (old and new) images

IMAGEWIDTH=640 IMAGEHEIGHT=250 # #

names of old and new default files

FILEDEFAULTORIG=default.${FILEEXT} FILEDEFAULTNEW=default_new.${FILEEXT} #

#

now create selection of default files with random file names

# #

create our images subdirectory is present

if [ ! -d "${SUBDIR}" ]; then echo -e "${SUBDIR} not found please correct and try again!" else

if [ ! -e "${FILEDEFAULTORIG}" ]; then echo -e "Original default file ${FILEDEFAULTORIG} not found please correct and try again!" else

if [ ! -e "${FILEDEFAULTNEW}" ]; then 
   echo -e "New default file ${FILEDEFAULTNEW} not found please correct and try again!"
else

  # save and change IFS (necessary to avoid probles with spaces etc within file names) 
  OLDIFS=$IFS
  IFS=$'\n'

  # display info about old and new default files
  file ${FILEDEFAULTORIG}
  file ${FILEDEFAULTNEW}
  #
  md5sum ${FILEDEFAULTORIG}
  md5sum ${FILEDEFAULTNEW}


  # get the md5sums for the original default
  _MD5_ORIG=$(md5sum "${FILEDEFAULTORIG}"|cut -d\  -f1)

  FILELIST=$(find "${SUBDIR}" -type f -not -iname "*${BACKUPEXT}"  )

  for FILE in ${FILELIST}
    do

      _MD5_FILE=$(md5sum "${FILE}"|cut -d\  -f1)

      echo -e "${_MD5_FILE}\t\t${FILE}"

      if [ "${_MD5_FILE}" == "${_MD5_ORIG}" ]; then
        echo -e "An Original Default File : ${FILE}"

        _DIRNAME="${FILE%/*}"
        _FILE_BASENAME="${FILE##*/}"
        _FILE_BASENAME0="${_FILE_BASENAME%.*}"
        _FILE_EXTENSION="${FILE##*.}"
        _FILE_BACKUP="${_DIRNAME}/${_FILE_BASENAME0}.${BACKUPEXT}"

        mv -b -f "${FILE}" "${_FILE_BACKUP}"
        cp -b "${FILEDEFAULTNEW}" "${FILE}" 

      fi


    done



  # restore IFS
  IFS=$OLDIFS#

fi

fi fi

------------------------------------------------------------

Note when copying into the new script files to get the right line endings! ie LF and not CR+LF

0

Firstly I would try to solve using a duplicate "test" local server, preferably Linux based, as bash/linux scripting lends itself better to this sort of problem. Only after successful testing would I then load the different files back to the original server.

Then I hope you still have the original default.jpg (or whatever) image. I would then create say a md5 checksum of this image which I could compare with the checksums of your images saved in 'media/com_mtree/images' -- small bash script needed. This so that you can differentiate between the default image and any other images. On a checksum match the old files can be overwritten by the new default image.

I have no experience of either of the two add-ins (have just looked them up), it would be useful to check in advance if there might be different resolutions (size) of the default image, which would have to be individually replaced.

If you need more detailed help you can send me a pm.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.