How to save a image to the local file system ?

Started by kkae, July 03, 2017, 08:45:20 PM

Previous topic - Next topic

kkae

In my old Basic-Script I use the following code snipped to make a image with a reduced size for publishing at my homepage.

Set lImage = New IMImage
lImage.LoadFile(lFile.FileName)
lImage.Resize(cWidthPhoto,cHeightPhoto,imrmLanczos,True)
lImage.SaveFile(lText,imsfJPEG24Standard,cRatioPhoto)

I have no idea how to save binary data (I have only found writeTextFile-function) now.
How is the syntax 'v1/files/image' for the parameter imagesize to set a defined width/height ?

thrinn

Is it really necessary to do that from a script? I would use the Image Batch Processor (Commands -> Import and Export) which offers standard setting for this.
Thorsten
Win 10 / 64, IMatch 2018, IMA

kkae

For me it's necessary.
That's not the only thing the script does.
1) it create an xml-file with metadata of the files in the category and
2) for only the images I have changed (Image or metadata) the script creates the reduced image and also a small thumbnail image
    an stores the files to the different folders.

   

Mario

JavaScript cannot save anything to the local file system. This is for security reasons.
There are currently no features in IMWS which allow an app to "download" or "process" an image file or to save it to the local file system.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kkae

Hi Mario,

that's not a satisfactory  response and not consequent.
You implemented with IMatch.writetextfile writing to the local file system.

So I have to write an external Java or C++ programm which does the work of resizing and saving the images.

----
Other question:

Is there a possibility to start the Image Batch Processor from a script ?



Mario

Quotethat's not a satisfactory  response and not consequent.
You implemented with IMatch.writetextfile writing to the local file system.

Yes. I did. Because this allows app programmers to save text files to the local file system, by utilizing IMatch. IMatch writes the file, not the browser of JavaScript. Awesome.

QuoteSo I have to write an external Java or C++ programm which does the work of resizing and saving the images.
Sure. You can use Powershell, Java, C#, Python, C++, Go, Node.js or whatever you prefer.

If there is sufficient demand  from users (or I need it for new features) I will add an "image processor" to IMWS which can process, convert and save images. I have that one on my to-do list already.

QuoteIs there a possibility to start the Image Batch Processor from a script ?

No.  Not directly. The Batch Processor has over 120 parameters. Making this accessible from an app would require a very complex set of endpoints.
But you can run Favorites from an app, and you can create Favorites for Batch Processor Presets.
This should be helpful.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

Just a couple of comments:

In IM5 it was possible to call the batch processor by script. I used this to first sort images into landscape/portrait format and then
calling the batch processor with different presets. (Fortunately these apps are not on my "must have converted before I can use Im2017" list - and -
I can go the route over Favorites Mario mentioned).

I also use the functionality to resize images via script in IM5. I have a script which splits an image down the middle and another
which joins two images side by side. (Fortunately I don't use this much anymore and I should be able to use the D&P module to do this.)

Mario

QuoteIn IM5 it was possible to call the batch processor by script.

I don't even remember this anymore. It is very likely that you are the only user who has ever used that.

As you can see from the comments here in the community, and the feature requests boards:

a) There are not many users who write their own scripts
b) Things which are required by more than one user usually bubbly up in a feature request that gets more than one +1

My idea was to create an IMWS API for IMatch which covers a broad range of features. Basically everything I needed for the stock apps, plus a good share of what we had in IMatch 5 scripting, and of course plus everything available in IMatch Anywhere WebServicesTM.

It makes no sense to completely re-create all scripting classes and methods available in IMatch 5 - I'm pretty sure that many of those have never been used. Or maybe just by one user. Who may not even use IMatch anymore.

I will keep an eye on app-related feature requests in the FR board and implement what's needed in future updates. Just look at what was added in in the past three weeks:

Added/enhanced several endpoints
App Manager can hide apps
Closing prompts for apps
Next version uses the official app icons for favorites
Next version allows app favorites to control in which App Panel they run
...

-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kkae

Hello,

I now tried to realize the proposal of "Image Batch Processor" and "Favorites".
I created in IMatch a Image Batch Processor-Preset (kae_c_2002) and a new favorite set (Kae_WWW).
In Match it works and converts to files to the specified directory.

In my App I wrote a test function.
Result was ok [HTTP/1.1 200 OK 31ms], but nothing was done.


var catWwwTest = function() {

IMatch.favoritesList().then(function(response1) {
console.log(JSON.stringify(response1,null,2));

// get GUID of favorite
var favoriteSetName = 'Kae_WWW';
var result = jQuery.grep(response1.favorites, function(item,i){return item.name == favoriteSetName});
var guidFavSet = result[0].favorites[0].id;

IMatch.favoriteExecute({
guid: guidFavSet,
            id: '95732'
}).then(function(response2) {
console.log(JSON.stringify(response2,null,2));
},
function(error) {
console.log('Error: ' + error.status);
});

console.log('end');
},
function(error) {
console.log('Error: ' + error.status);
});

}


console output of an other function which get all file of a category

GET  XHR http://127.0.0.1:50519/v1/categories [HTTP/1.1 200 OK 63ms]
{
  "categories": [
    {
      "id": 149481,
      "path": "zzzzApptest",
      "files": [
        95732,
        255447,
        257201
      ],
      "filesCount": 3
    }
  ],
  "debug": {
    "runtime": "62ms"
  }


console output of the function catWwwTest, I get the correct GUID

GET XHR http://127.0.0.1:50519/v1/imatch/favorites/list [HTTP/1.1 200 OK 0ms]
{
  "favorites": [
    {
      "id": 1,
      "name": "Favoriten",
      "favorites": []
    },
    {
      "id": 4,
      "name": "Anwendungen",
      "favorites": []
    },
    {
      "id": 5,
      "name": "Kae_WWW",
      "favorites": [
        {
          "id": "A707903B-99BA-438F-BEFB-B0AF6EB81734",
          "type": "importexport",
          "name": "kae_c_2002",
          "description": ""
        }
      ]
    }
  ]
}
end
POST XHR http://127.0.0.1:50519/v1/imatch/favorites/execute [HTTP/1.1 200 OK 31ms]
{
  "result": "ok"
}

Mario

Did you check the IMatch log file for warnings and errors?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kkae

I checked the logfile and see no errors.
In the attached file is a excerpt of the logfile.
First: logfile when calling the favorite in IMatch, all works fine.
Second: call of my testapp in the browser, nothing came after CIMatchIMWS::HandlerPOST_FavoriteExecute

Mario

#11
I see. It seems that IMWS does currently only support favorites of type category, folder, app, collection, application, md template. No import & export favorites, sorry.

One of the problems is, Import & Export modules expect data via drag & drop. This cannot be 'simulated' by a favorite. Some modules fall back to using the current selection and might work in some circumstances, but that's a bit fuzzy. Actually, I've just fixed a bug the other week, caused by when the user attempted to run a import & export favorite via a keyboard shortcut. This does not (cannot) work. And the same logic is used by IMatch apps.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mario

Hah! I made it work.

I have changed the processing of Import & Export favorites so that they 'simulate' a dropped file set by using the current selection in the file window.
This may not work for all potential situations, but for the majority. And this now also allows Apps run tun Import & Export favorites.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

kkae


Thanks.
Let's repeat with my words that I have understood it right. I have to do in my App the following

1. call gotocollection() which makes my collection (with about 5000 images) active
2. call selectFiles() whitch selectes the files I want to rezize
3: call the favorite

or

can use you/can you use the files-ids listed parameter id/idlist in the favoriteExecute() function for drag and drop simulation ?


Mario

Quoteds listed parameter id/idlist in the favoriteExecute() function for drag and drop simulation ?

Probably I could somehow route this through. But this would require changes in many areas.
Add a feature request for this. If other app authors also need something like this I may look into it in a later version.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Mario

I have to correct myself - sometimes I think further ahead when designing things than I later remember... ::)

I already had the routing in place, just needed to add a special case for running Import & Export presets as favorites via IMWS. Works now.
The id / idlist used to call the Favorite is used as the input for the Batch Processor.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook