Want more features on Pastebin? Sign Up, it's FREE!
Guest

photo_thumbElem.sh

By: phillips321 on May 9th, 2011  |  syntax: Bash  |  size: 4.29 KB  |  views: 206  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # ---------------------------------------------------------------------
  4. # limitations: cf convert pour la conversion en .jpg
  5. #
  6. # dépend des scripts suivant :
  7. # - photo_thumbCheckExist.sh
  8. # librairies
  9. # - convert
  10. #
  11. # ameliorations
  12. # - auto-orient
  13. # ---------------------------------------------------------------------
  14.  
  15. # ---------------------------------------------------------------------
  16. # init/config
  17. # ---------------------------------------------------------------------
  18.  
  19. # thumnails names
  20. export XLname="SYNOPHOTO:THUMB_XL.jpg"
  21. export Lname="SYNOPHOTO:THUMB_L.jpg"
  22. export Bname="SYNOPHOTO:THUMB_B.jpg"
  23. export Mname="SYNOPHOTO:THUMB_M.jpg"
  24. export Sname="SYNOPHOTO:THUMB_S.jpg"
  25.  
  26. # thumnails size
  27. export XLsize="1280x1280"
  28. export Lsize="800x800"
  29. export Bsize="640x640"
  30. export Msize="320x320"
  31. export Ssize="160x160"
  32.  
  33. # fichier temporaire crée par checkThumbExist
  34. fileTmpDiff="/tmp/thbExist918diff"
  35.  
  36. # ---------------------------------------------------------------------
  37. # coeur du programme
  38. #
  39. # rem: a ameliorer pour tenir compte de tous les formats image supportés
  40. #
  41. # limitations: extensions supportés jpg JPG
  42. # ---------------------------------------------------------------------
  43.  
  44. # element a convertir
  45. fullPathToPic=$@
  46.  
  47. # normalement cette étape du test sur @eaDir est désormais inutile car la commande find du fichier maitre l'intègre déjà
  48. # (this step is not useful as master script with "find" command includes this test)
  49. # test @eaDir (on le garde par robustesse au cas où...)
  50. isNot_eaDir=`echo $fullPathToPic | grep -v "@eaDir"`
  51.  
  52. if [[ -z $isNot_eaDir ]]
  53. then
  54.  
  55.   # fichier image non traité car contient @eaDir dans le path
  56.   echo " "
  57.   echo "SKIP "$fullPathToPic" : in @eaDir thumbnail sub-folder"
  58.  
  59. else
  60.  
  61.   # Recupere le noms et le dossier de l'element
  62.   picName=`echo $fullPathToPic |  awk -F\/ '{print $NF}'`
  63.   picDir=`echo $fullPathToPic | sed s/"${picName}"//g | sed s/.$//`
  64.  
  65.   # vérification que les miniatures n'existe pas déjà
  66.   photo_thumbCheckExist.sh "${picDir}" "${picName}"
  67.  
  68.   # si diff vide alors les miniatures existent deja
  69.   isNot_thumb=`cat $fileTmpDiff`
  70.  
  71.   if [[ -z $isNot_thumb ]]
  72.   then
  73.  
  74.     # fichier non traité car les miniatures existent (thumbnails exist already)
  75.     echo " "
  76.     echo "SKIP "$fullPathToPic" : all thumbnails already exist"
  77.  
  78.   else
  79.  
  80.     echo " "
  81.     echo "TREATMENT "$fullPathToPic
  82.  
  83.     # conversion en cascade (XL -> L -> B -> M -> S)
  84.     # ----------------------------------------------
  85.    
  86.     # Creation du repertoire s'il n'existe pas (directory creation if not existing)
  87.     if [[ !(-d "$picDir"/"@eaDir"/"$picName") ]]
  88.     then
  89.        
  90.         mkdir -p "$picDir""/@eaDir/""$picName"
  91.         # modification of rights to be readable and executable by "others" (like photostation...)
  92.         chmod 775 "$picDir"/"@eaDir"/"$picName"
  93.    
  94.     fi
  95.    
  96.     # si le fichier n'existe pas on le crée sinon on ne fait rien
  97.     # (creation of thumbnail if it doesn't exist)
  98.     if [[ !(-f "$picDir"/"@eaDir"/"$picName"/"$XLname") ]]
  99.     then
  100.         convert -size $XLsize "$picDir""/""$picName" -resize $XLsize -auto-orient -flatten "$picDir"/"@eaDir"/"$picName"/"$XLname"
  101.         echo "   -- "$XLname" thumbnail created"
  102.     fi
  103.    
  104.     if [[ !(-f "$picDir"/"@eaDir"/"$picName"/"$Lname") ]]
  105.     then
  106.         convert -size $XLsize "$picDir""/@eaDir/""$picName""/""$XLname" -auto-orient -resize $Lsize "$picDir""/@eaDir/""$picName""/""$Lname"
  107.         echo "   -- "$Lname" thumbnail created"
  108.     fi
  109.    
  110.     if [[ !(-f "$picDir"/"@eaDir"/"$picName"/"$Bname") ]]
  111.     then
  112.         convert -size $Lsize "$picDir""/@eaDir/""$picName""/""$Lname" -auto-orient -resize $Bsize "$picDir""/@eaDir/""$picName""/""$Bname"
  113.         echo "   -- "$Bname" thumbnail created"
  114.     fi
  115.    
  116.     if [[ !(-f "$picDir"/"@eaDir"/"$picName"/"$Mname") ]]
  117.     then
  118.         convert -size $Bsize "$picDir""/@eaDir/""$picName""/""$Bname" -auto-orient -resize $Msize "$picDir""/@eaDir/""$picName""/""$Mname"
  119.         echo "   -- "$Mname" thumbnail created"
  120.     fi
  121.    
  122.     if [[ !(-f "$picDir"/"@eaDir"/"$picName"/"$Sname") ]]
  123.     then
  124.         convert -size $Msize "$picDir""/@eaDir/""$picName""/""$Mname" -auto-orient -resize $Ssize "$picDir""/@eaDir/""$picName""/""$Sname"
  125.         echo "   -- "$Sname" thumbnail created"
  126.     fi
  127.   fi
  128.  
  129. fi
clone this paste RAW Paste Data