Page 1 sur 1

Redimensionner une image trop grosse

MessagePublié: 10 Juil 2007 à 09:49
par billbock
Il arrive bien sur qu'il faille redimensionner une photo pour un annuaire web

Voici un agent permettant de redimensionner la taille de l'image
(ex : une photo de 1Mo passe à 9Ko)

Pour cela il faut installer un soft s'appelant "Image Magick" sur serveur domino

http://www.imagemagick.org/script/download.php

Il faut creer un fichier Batch à mettre dans un repertoire du serveur (ex : D:\manipImages)

Code : Tout sélectionner
::@echo off

::Fichier jpg obligatoire
if not exist %1 (echo Le fichier %1 est introuvable&goto erreur)

set fichier=%1
set IGG=%2

for /f %%a in ('identify -format %%h-%%w-%%b %fichier%') do set infos=%%a
if "%infos%" == "" goto erreur

for /f "tokens=1,2,3 delims=- " %%a in ('echo. %infos%') do set h=%%a&set l=%%b&set p=%%c

if %h% GTR 400 goto modif
if %l% GTR 400 goto modif
if %p% GTR 30000 goto modif
goto noModif

:modif
::echo Transformation requise
convert -thumbnail 140x150 "%fichier%" "%IGG%.jpg"
if ERRORLEVEL 1 goto erreur
goto ok

:noModif
::echo Pas de transformation
copy "%fichier%" "%IGG%.jpg"
if ERRORLEVEL 1 goto erreur
goto ok

:erreur
exit 1
::echo 1

:ok
exit 0
::echo 0


la ligne de commande lancer est la suivante

D:\manipulationsImages\convImg.bat <cheminimg> <nomimageredim>

<cheminimg>, est l'emplacement ou se trouve l'image à redimensionner
<nomimageredim> est le nom de l'image en sortie


Le lotus Script pour lancer cela est le suivant

(J'utilise un flag pour lancer l'agent de maniere planifiée...)

Code : Tout sélectionner
Dim sess As notessession
Dim db As notesdatabase
Dim vueConfig As Notesview
Dim docConfig As notesdocument

Dim vueRedim As NotesView
Dim docRedim As NotesDocument
Dim docTemp As NotesDocument

Dim repertoire As String
Dim commandLine As String
Dim commandLineBatch As String

Dim nomimage As String
Dim igg As String

Dim itemFile As NotesItem
Dim strFileName As String
Dim embobj As NotesEmbeddedObject
Dim strNomFileNameSansEspace As String
Dim strRepName As String

Dim strRepNameRedim As String

Sub Initialize
   Set sess = New notessession
   Set db = sess.currentdatabase
   Set vueConfig = db.getView("vLkpConfig")
   Set docConfig = vueConfig.GetFirstDocument

   'recuperation du repertoire de détachement et de la ligne de commande

   Call CreationLog(db,"Action","Redimensionnement Photo","","","","Debut de l'agent de Redimensionnement Photo",0,Nothing)
   Call RecupConfig(docConfig)

   'teste si le repertoire existe

   If RepExist(repertoire) = False Then
      Call CreationLog(db,"Error","Redimensionnement Photo","","","","Le répertoire de traitement photo n'existe pas",0,Nothing)
      Exit Sub
   End If

   'teste si le batch image magick existe

   If FileExist(repertoire & "\convImg.bat") = False Then
      Call CreationLog(db,"Error","Redimensionnement Photo","","","","Le batch de traitement photo n'existe pas",0,Nothing)
      Exit Sub
   End If

   'Se positionner dans le repertoire ou se trouve le batch

   Chdrive Left$(repertoire,1)
   Chdir repertoire + "\"

   Set vueRedim = db.getview("CNomPhotoRedim")
   Set docredim = vueRedim.GetFirstDocument
   Do Until docRedim Is Nothing
      Set doctemp = vueRedim.GetNextDocument(docRedim)
      Call TraitementRedim
      Set docRedim = docTemp
   Loop
   Call CreationLog(db,"Action","Redimensionnement Photo","","","","Fin de l'agent de Redimensionnement Photo",0,Nothing)
End Sub


Sub RecupConfig(doc As notesdocument)
   repertoire =  doc.RepertoirePhotoIMGMAGIC(0)
   commandLine = doc.CommandLineIMGMAG(0)
End Sub

Sub TraitementRedim
   'calcul du nom du fichier image
   'suppression des caracteres spéciaux dans le nom

   igg = docRedim.IGG(0)
   If igg = "" Then
      nomimage = SuppCaracSpeciaux(db,Ucase(docRedim.userNom(0)))
   Else
      nomimage = igg
   End If
   
   'Detachement du fichier

   Call DetachImage

   'Retraitement de la ligne de commande Image Magic

   commandLineBatch = Replace(Replace(commandLine,"<cheminimg>",strRepname),"<nomimageredim>",nomimage)
   'Shell
   
   If RedimBatch = 33 Then
   'Destruction PJ dans le doc si Shell OK
      Call docredim.RemoveItem("$File")
      Call docredim.RemoveItem("ImageRedim")
   'Attachement de l'image redimensionne dans le champ texte Riche ImageRedim
      Call AttachImage
   'Flag ImageRedim vidé
      docRedim.FlagImageRedim = ""
      Call docredim.computewithForm(True,True)
      Call docredim.Save(True,True)
   End If
   
   'Kill des photos sur le serveur
   If FileExist(strRepName) Then
      Kill StrRepName
   End If
   
   If FileExist(strRepNameRedim) Then
      Kill   strRepNameRedim
   End If
End Sub

Sub DetachImage
   Set itemFile = docredim.GetFirstItem("$File")
   strFileName = itemFile.Values(0)
   Set embobj = docredim.GetAttachment(strFileName)
   strNomFileNameSansEspace = Replace(strFileName," ","+")
   strRepName = Trim(repertoire + "\" + strNomFileNameSansEspace)
   strRepNameRedim = Trim(repertoire + "\" + nomImage + ".JPG")
   Call embobj .ExtractFile(strRepName)
End Sub

Sub AttachImage
   Dim rtitem As NotesRichTextitem
   Set rtitem = New NotesRichTextItem(docRedim,"ImageRedim")
   Call rtitem.EmbedObject(EMBED_ATTACHMENT,"",strRepNameRedim)
End Sub

Function RedimBatch As Integer
   On Error Goto GestionErreur
   Dim intTaskId As Integer
   intTaskid = Shell(commandLineBatch, 1 )
   Sleep 10
   RedimBatch = intTaskid
   Exit Function
GestionErreur :
   RedimBatch = 1
   Resume Next   
End Function

MessagePublié: 10 Juil 2007 à 09:54
par Stephane Maillard
Salut,

Sympa l'idée de passé par Image Magick.

MessagePublié: 10 Juil 2007 à 10:00
par billbock
c'est surtout tres rapide