Programmation sous MacOs

Bonjour,

Le sujet a déjà été abordé un peu mais j’ai un besoin spécifique et je sais pas par où commencer.

Mon besoin:
Je prends des photos et je veux les publier sur un site web.
Le site web en question est tout bête, il utilise les infos exif du fichier pour afficher ça joliment.

Avant quand j’étais petit, j’étais sous windows, j’ai donc fait une appli qui se place dans le “sendto” de windows.
Ca me permettait de faire click droit sur la photo et sendto mon site web.
En gros l’appli fait: affiche la photo, lecture des infos exif de la photo pour pouvoir les modifier, resize de la photo et envoie par FTP sur le serveur WEB.
Pour ça j’ai developpé une appli en C++ sous Visual Studio qui s’appuie sur les libs exiv, imagemagick , curl et wxWidget , ça tient en 30 lignes de code, c’est cool.
J’ai choisi cette méthode, car je connais bien le dev sous windows.

Maintenant je suis avec Macos, toutes mes photos sont dans iPhoto.
et je voudrais faire la même chose, je sélectionne quelques photos et via un menu tout est balancé sur mon site. Mon problème: comment je fais…
Un applescript?
Un script automator?
Un plugin iPhoto fait avec XCode?
Autre?

Qu’est ce qui vous semble le plus à même de faire ce que je veux?
Et surtout vu que j’y connais rien en prog Macos, par quoi je commence, ya tellement de tutos et autre sur le web que je suis un peu perdu.

Voilà voilà
Merci
Duffy

Je pensais à une clé à molette.

Il me semble que toutes les librairies que tu as cités sont cross plateformes … (d’ailleurs je serais interessé par les sources, juste pour jetter un oeil si ça te dérange pas).
Tu as tenté de recompiler sur ton mac et de tester, avant de replacer ça dans un *like ?

(toute façon sous mac y’a qu’un boutton, donc boutton droit envoyer vers … :)’</je suis un gros boulet>)

roh putain si unreal est modo, on est mal barré :crying: (quoi que la sévérité va peut-être revenir!)

J’ai un peu honte de montrer ce code, car il est tout crade, mais le but était de faire un truc qui marche et de le faire vite.

[codebox] // For compilers that support precompilation, includes « wx/wx.h ».
#include « wx/wxprec.h »
#ifndef WX_PRECOMP
#include « wx/wx.h »
#endif
#include « wx/image.h »
#include « wx/file.h »
#include « wx/filename.h »
#include « wx/protocol/ftp.h »

#include <Magick++.h>
using namespace Magick;

#include « exivsimple.h »

#include « ftp.h »

// derived classes
class cGUApp: public wxApp
{
virtual bool OnInit();
};

class cGUPanelImage: public wxPanel
{
public:
void LoadImage( wxString sFilePath );
void OnPaint (wxPaintEvent & event);
wxImage m_Image;
wxSize m_Size;
bool m_bHori;

DECLARE_EVENT_TABLE()
};

class cGUDialog: public wxDialog
{
public:
cGUDialog(wxFrame parent, wxWindowID id, const wxString &title, const wxString &sFilePath );
void OnSize( wxSizeEvent & event );
void Manage();
private:
wxBoxSizer
m_pTopSizer;
wxBoxSizer* m_pLogPwdSizer;
wxBoxSizer* m_pWidthHeightSizer;
wxBoxSizer* m_pButtonSizer;

 cGUPanelImage m_PanelImage;
 wxTextCtrl m_FTP;
 wxTextCtrl m_Directory;
 wxTextCtrl m_Login;
 wxTextCtrl m_Password;
 wxTextCtrl m_HeadLine;
 wxTextCtrl m_Caption;

 wxTextCtrl m_Width;
 wxTextCtrl m_Height;

 wxString m_sHeadLine;
 wxString m_sCaption;

 wxString m_sFilePath;
 wxString m_sSmallFilePath;
 wxString m_sSmallFileName;

 ftp m_FtpConnection;

DECLARE_EVENT_TABLE()
};

BEGIN_EVENT_TABLE(cGUDialog, wxDialog)
EVT_SIZE (cGUDialog::OnSize)
END_EVENT_TABLE()

BEGIN_EVENT_TABLE(cGUPanelImage, wxPanel)
EVT_PAINT(cGUPanelImage::OnPaint)
END_EVENT_TABLE()

IMPLEMENT_APP(cGUApp)

bool cGUApp::OnInit()
{
InitializeMagick(NULL);
wxInitAllImageHandlers();
wxString sFilePath;
if ( argc == 2 )
{
sFilePath = argv[1];
cGUDialog dlg(NULL,-1,« mGallery », sFilePath );
int x = dlg.ShowModal();
if ( x == 5100 )
{
dlg.Manage();
}
else
{
}
}
return false;
}

cGUDialog::cGUDialog(wxFrame *parent, wxWindowID id, const wxString &title, const wxString& filePath )
: wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
{
m_pTopSizer = new wxBoxSizer( wxVERTICAL );
m_pLogPwdSizer = new wxBoxSizer( wxHORIZONTAL );
m_pWidthHeightSizer = new wxBoxSizer( wxHORIZONTAL );
m_pButtonSizer = new wxBoxSizer( wxHORIZONTAL );

 m_sFilePath = filePath;
 int lSlashPos = filePath.Last( '\\' );
 m_sSmallFileName = "_" + filePath.Right( filePath.Length() - lSlashPos - 1 );
 m_sSmallFilePath = filePath.Left( lSlashPos + 1 );

 HIMAGE hImage = OpenFileImage(filePath);
 if ( ReadMeta(hImage, "Iptc.Application2.Headline", m_sHeadLine.GetWriteBuf(256), 256 ) == 0 )
 {
	 m_sHeadLine.UngetWriteBuf();
 }
 else
 {
	 m_sHeadLine.UngetWriteBuf();
	 m_sHeadLine.Empty();
 }
 if ( ReadMeta(hImage, "Iptc.Application2.Caption", m_sCaption.GetWriteBuf(2000), 2000 ) == 0 )
 {
	 m_sCaption.UngetWriteBuf();
 }
 else
 {
	 m_sCaption.UngetWriteBuf();
	 m_sCaption.Empty();
 }
 FreeImage(hImage);

 m_PanelImage.LoadImage( filePath );
 m_PanelImage.Create( this, -1, wxDefaultPosition, m_PanelImage.m_Size );
 m_pTopSizer->Add( &m_PanelImage, 1, wxEXPAND | wxALL | wxCENTER, 10 );

 m_FTP.Create( this, -1, wxString(FTP) );
 m_pTopSizer->Add( &m_FTP, 0, wxLEFT | wxRIGHT | wxEXPAND, 10 );
 m_Directory.Create( this, -1, wxString(DIR) );
 m_pTopSizer->Add( &m_Directory, 0, wxLEFT | wxRIGHT | wxEXPAND, 10 );

 m_Login.Create( this, -1, LOGIN );
 m_Password.Create( this, -1, PASSWORD, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD);
 m_pLogPwdSizer->Add( &m_Login, 1, wxEXPAND, 0 );
 m_pLogPwdSizer->Add( &m_Password, 1, wxEXPAND, 0 );
 m_pTopSizer->Add( m_pLogPwdSizer, 0, wxLEFT | wxRIGHT | wxEXPAND, 10 );

 m_HeadLine.Create( this, -1, m_sHeadLine, wxDefaultPosition, wxDefaultSize );
 m_pTopSizer->Add( &m_HeadLine, 0, wxEXPAND | wxALL, 10 );

 m_Caption.Create( this, -1, m_sCaption, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
 m_pTopSizer->Add( &m_Caption, 0, wxEXPAND | wxLEFT | wxRIGHT , 10 );

 m_Width.Create( this, -1, "800" );
 m_Height.Create( this, -1, "600" );
 m_pWidthHeightSizer->Add( &m_Width, 1, wxEXPAND, 0 );
 m_pWidthHeightSizer->Add( &m_Height, 1, wxEXPAND, 0 );
 m_pTopSizer->Add( m_pWidthHeightSizer, 0, wxLEFT | wxRIGHT | wxEXPAND, 10 );

 m_pButtonSizer->Add( new wxButton( this, wxID_OK, "OK" ), 0, wxALL, 10 );
 m_pButtonSizer->Add( new wxButton( this, wxID_CANCEL, "Cancel" ), 0, wxALL, 10 );
 m_pTopSizer->Add( m_pButtonSizer, 0, wxCENTER, 0 );

 SetSizer( m_pTopSizer );	  // use the sizer for layout
 m_pTopSizer->SetSizeHints( this );   // set size hints to honour minimum size
 CenterOnScreen();

}

void cGUDialog::Manage()
{
m_sHeadLine = m_HeadLine.GetValue();
m_sCaption = m_Caption.GetValue();

 //Update Title/Caption
 HIMAGE hImage = OpenFileImage(m_sFilePath);
 if ( m_sHeadLine.Length() != 0 )
	 ModifyMeta( hImage, "Iptc.Application2.Headline", m_sHeadLine, string );
 else
	 RemoveMeta( hImage, "Iptc.Application2.Headline" );
 if ( m_sCaption.Length() != 0 )	
	 ModifyMeta( hImage, "Iptc.Application2.Caption", m_sCaption, string );
 else
	 RemoveMeta( hImage, "Iptc.Application2.Caption" );



 SaveImage( hImage );
 FreeImage( hImage );

 //Resize
 long lWidth;
 long lHeight;
 m_Width.GetValue().ToLong( &lWidth );
 m_Height.GetValue().ToLong( &lHeight );
 Geometry geo( lWidth, lHeight );
 std::string sFilePath = m_sFilePath;
 std::string sSmallFilePath = m_sSmallFilePath + m_sSmallFileName;
 Image Img;
 Img.read( sFilePath );
 Img.resize( geo );
 Img.write( sSmallFilePath );
 
 //Upload
 wxString sTemp;
 char* pBuffer = new char[512];
 sTemp = m_FTP.GetValue();
 memcpy( pBuffer, sTemp.data(), sTemp.length()+1 );
 m_FtpConnection.DoOpen( pBuffer );
 sTemp = "user " + m_Login.GetValue() + ":" + m_Password.GetValue();
 memcpy( pBuffer, sTemp.data(), sTemp.length()+1 );
 m_FtpConnection.DoLogin( pBuffer );
 m_FtpConnection.DoBinary();
 sTemp = "cd " + m_sSmallFilePath;
 memcpy( pBuffer, sTemp.data(), sTemp.length()+1 );
 m_FtpConnection.DoLCD( pBuffer );
 sTemp = "cd " + m_Directory.GetValue();
 memcpy( pBuffer, sTemp.data(), sTemp.length()+1 );
 m_FtpConnection.DoCD( pBuffer );
 memcpy( pBuffer, m_sSmallFileName.data(), m_sSmallFileName.length()+1 );
 m_FtpConnection.DoPut( pBuffer );
 delete pBuffer;

}

void cGUPanelImage::LoadImage( wxString sFilePath )
{
m_Image = wxImage(sFilePath);
m_bHori = ( m_Image.GetWidth() > m_Image.GetHeight() );
if ( m_bHori )
{
m_Size.SetWidth( 300 );
m_Size.SetHeight( 300 * m_Image.GetHeight() / m_Image.GetWidth() );
}
else
{
m_Size.SetHeight( 200 );
m_Size.SetWidth( 200 * m_Image.GetWidth() / m_Image.GetHeight() );
}
}

void cGUDialog::OnSize( wxSizeEvent & e)
{
wxDialog::OnSize(e);
m_PanelImage.Refresh();
}

void cGUPanelImage::OnPaint (wxPaintEvent &)
{
wxPaintDC dc(this);
wxSize size = GetSize();
wxSize sizeImage = size;
if ( m_bHori )
{
sizeImage.SetHeight( size.GetWidth() * m_Image.GetHeight() / m_Image.GetWidth() );
}
else
{
sizeImage.SetWidth( size.GetHeight() * m_Image.GetWidth() / m_Image.GetHeight() );
}
dc.DrawBitmap(m_Image.Scale( sizeImage.GetWidth(), sizeImage.GetHeight(), wxIMAGE_QUALITY_NORMAL ), (size.GetWidth()-sizeImage.GetWidth())/2, 0, true);
}[/codebox]

Ça se fait très bien avec Automator :

iPhoto => Obtenir les éléments iPhoto sélectionnés
Aperçu => Redimensionner les images

(Si tu ne veux pas modifier les images, Automator propose automatiquement une action « copier les éléments »)

Et pour le FTP, il n’y a rien d’inclus, mais tu peux télécharger une action toute faite là :

http://www.apple.com/downloads/macosx/auto…ploadtoftp.html

Après, j’ai zappé pour les données Exif, mais je pense qu’en cherchant EXIF et Automator, tu devrais trouver ton bonheur :slight_smile:

Il y a un plug in pour iPhoto qui permet d’uploader sur google/picasa. ça rajoute une option dans le menu fichier => exporter.

Je donne ça comme une piste à explorer …

Bah finalement Automator marche au poil, juste un truc…
Quand je sélectionne plusieurs photos et exécute le script, l’action relative à l’édition des données exif me demande une seule fois les données à rentrer du coup ces données sont appliquées à toutes les images et c’est balot. Une idée sur comment changer ce comportement?
Duffy