Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Import online image

New Here ,
Aug 03, 2013 Aug 03, 2013

Hi people,

I'm new to Photoshop scripting and i'm trying to create a script that creates a new layer and imports an online image based on selection made by user (to import placeholder using placehold.it)

          var document = app.activeDocument; 

          var width = document.selection.bounds[2].replace(' px','');

          var height = document.selection.bounds[3].replace(' px','');

          app.open(new File("http://placehold.it/"+width + "x" + height)); // Here is my problem I can't import an image like that

          app.activeDocument.activeLayer.copy();

          app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

          document.paste();

So is there a way to open a distant image from jsx ?

TOPICS
Actions and scripting
2.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Mentor ,
Aug 04, 2013 Aug 04, 2013

Here is a link to a script by Jeff Tranberry that will let you open a file from a web URL http://www.mouseprints.net/old/dpr/OpenImageFromWeb.jsx

I couldn't find a link to the original script but that version works with the URL used. A problem I have run into with both this version and the original version is that it doesn't work will every URL. I think it has something to do with the web server. For example I can not get it to download any images from the several sites I have using the same hosting service.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2013 Aug 04, 2013

Been some time I do recall having some problems web servers url and html. I also player with getting all images on a web page into a stack. The script did bot always work.  There is no standard web site design, writing a script to handle all web design is beyond my abilities.  You may also want to look at http://www.mouseprints.net/old/dpr/StackWebPageImages.jsx  on my web site as well as Adobe Javascript sample socket script I started with. Its one of the scripts included in the optional Photoshop scripting downloads from Adobe's web site.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 04, 2013 Aug 04, 2013

I don't think is has any thing to do with the web site design. I think there is something about some servers that causes this script to fail. For example here is a vaild URL that the script will not download. http://www.ps-scripts.com/images/logo1.gif

Instead of getting the image it gets a '404 Not Found' message. But that same URL in a browser shows the image.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2013 Aug 04, 2013

I added

socket.write("GET " + sImg +" HTTP/1.1\nHost: " + domain + "\nAccept-Encoding: gzip, deflate\nConnection: keep-alive\n\n");

to be able to read some file that was on other website (mod deflate could cause some trouble)

I made this script work for any kind of images but the time is much too long, (3/4 seconds to successfully import an image on the canvas)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 04, 2013 Aug 04, 2013

Thanks for that. It does let me download and open the logo1.gif. But it hangs the ExtendScript Toolkit editor/debugger.

Changing that line to

socket.write("GET " + sImg +" HTTP/1.0\nHost: " + domain + "\nAccept: image/gif, image/x-xbitmap, image/png, image/jpeg, */*\n\n");

is a lot faster, but still hangs ESTK.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2013 Aug 04, 2013

Thank you two helped a lot...

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 05, 2013 Aug 05, 2013

Finally I created a panel using Adobe Configurator 4 and added a new HTML Widget with the script

_Adobe.download('url of the file' ...)

There is an example given by Adobe when you start Adobe Configurator 4.

and then I invoke the jsx that use the file and remove it at the end.

This solution is rly fast, the file is downloaded instantly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2013 Aug 05, 2013
LATEST

I do not like the way you need to configure panels for each version of Photoshop using the latest version of the configurator. Why do you need a different install for each version of Photoshop. I rather just install a Photoshop scripts that work with all versions of Photoshop. Panels just take up additional space as it is  Photoshop has too many pallets and panels. I see little difference in having an addition GUI panel or Having an additional Script dialog, If you need fast access to your script you can always create an action with an assigned F key that uses the script you want quick access to. Faster then maintaining Panels installation for each Photoshop version installing then and using them. I do realize this is my opinion your may differ.

JJMack
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines