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

Opening a remote image in Photoshop

Explorer ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

In a script code is there a way to ask photoshop to download a photo from the internet and open it?


Example; I have an image on the internet "https://upload.wikimedia.org/wikipedia/commons/e/ec/Sunset_in_Manaus.jpg"

I would like it to open in Photoshop via script. Would it be possible?

* Photoshop would download the photo to the pc and then open it.



TOPICS
Actions and scripting

Views

781

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Jan 12, 2021 Jan 12, 2021

If you can connect to the servers html port I had a scripot the could. I do not thinsk it could  do is with https. I think I rememver I was able to change https to http and  do it. I believe I took the socket cone from and adobe sample script. The Script will most like not work  in 2021

 

// OpenImageFromWeb.jsx
// Copyright 2006-2009
// Written by Jeffrey Tranberry
// Photoshop for Geeks Version 3.0
// modified by MLH
// modified by JJMACK 2010
/*
<javascriptresource>
<about>$$$/JavaScripts/Ope
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

If you can connect to the servers html port I had a scripot the could. I do not thinsk it could  do is with https. I think I rememver I was able to change https to http and  do it. I believe I took the socket cone from and adobe sample script. The Script will most like not work  in 2021

 

// OpenImageFromWeb.jsx
// Copyright 2006-2009
// Written by Jeffrey Tranberry
// Photoshop for Geeks Version 3.0
// modified by MLH
// modified by JJMACK 2010
/*
<javascriptresource>
<about>$$$/JavaScripts/OpenImageFromWeb/About=JJMack's OpenImageFromWeb.^r^rCopyright 2010 Mouseprints.^r^rJJMack's Script.^rOpen Image From Web as a Placed smart object layer!</about>
<category>JJMack's Script</category>
</javascriptresource>
*/

/*
 Description:
 This sample script shows how to download images from a web server using the
 Socket object.
*/
 
// Note: Socket.read() parameter & behavior
// Socket.read() will read or time out. It may not read all data fromserver. <---------------
// Socket.read(999999) will read 999999 bytes, or timeout, or socket will be
// closed by the server.
 
// enable double clicking from the
// Macintosh Finder or the Windows Explorer
#target photoshop
 
// Make Photoshop the frontmost application
app.bringToFront();
 
/////////////////////////
// SETUP
/////////////////////////

var html = "";
var request = "";
var url = "";
var binary = "";
var requesthtml = "";
var socket = new Socket;
var domain = "www.mouseprints.net" // the domain for the file we want
var sImg = "/old/dpr/JJMack8btiSrgb.png"; // the rest of the url for the file we want
var port = ":80"; // the port for the file we want

 
/////////////////////////
// MAIN
/////////////////////////
var url = prompt("Enter the image's full URL http://domain/full image path",url);   // prompt for domain name
if (url != null && url != ""){
	if ( (url.indexOf("https://") != -1) || (url.indexOf("HTTPS://") != -1)) {
		//alert("Strip)")
		save  = url.substr(8,);
		url =  "http://" + save;
	}
	if ( (url.indexOf("http://") != -1) || (url.indexOf("HTTP://") != -1)  ) {
		domainPathLength = url.length - "http://".length; 
		domainPath = url.substr(7, domainPathLength);
		pathOffset = domainPath.indexOf("/"); 
		domain = domainPath.substr(0, pathOffset);
		sImg = domainPath.substr(pathOffset, domainPath.length - pathOffset );
		// Isolate Image name 
		var Name =  sImg
		var imagePath = "";
		while (Name.indexOf("/") != -1 ) {				// Strip Path
			imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);
			Name = Name.substr(Name.indexOf("/") + 1 ,);		
			}
		//alert("domain = " +  domain + " , Image = " + sImg + " Image File Name = " + Name);
		if ( domain != "" && sImg != "" && sImg != "/" && Name.indexOf(".") != -1 ) {
			var f = File("~/Desktop/" + Name); // Image file name
			f.encoding = "binary"; // set binary mode
			f.open("w");

			if (socket.open(domain + port, "binary")){
				//alert("GET " + sImg +" HTTP/1.1\n\n");
				requesthtml ="\n\nDmain:" + domain + " Port" + port + " binary\n"
				//request ="GET " + sImg +" HTTP/1.0\n\n"
				request ="GET " + sImg +" HTTP/1.1\nHost: " + domain + "\nAccept: image/gif, image/x-xbitmap, image/png, image/jpeg, */*\n\n";
				//alert(request);
 				socket.write(request); // get the file
				//alert("After Request");
				var binary = socket.read(99999999);
				//alert("remove Header");
				binary = removeHeaders(binary);
				//alert("Write File")
				f.write(binary);
				socket.close();
				} 
			else { alert("Connection to Domain:" + domain + " Port" + port + " Failed   ");}
			
			//alert("Close");

			f.close();

			if (binary.length != 0) {
				//alert ("file length = " + binary.length );

				if(app.documents.length == 0) { 
					//app.documents.add([width] [, height] [, resolution] [, name] [, mode] [, initialFill] [,pixelAspectRatio] [, bitsPerChannel] [,colorProfileName])
					app.documents.add(new UnitValue(3840,'px'), new UnitValue(2160,'px'), 72, null, NewDocumentMode.RGB, DocumentFill.WHITE, 1,BitsPerChannelType.EIGHT, "sRGB IEC61966-2.1" );
					}
				placeSmartObject( f );
				} 

			f.remove(); // Remove temporary downloaded files
			}
		else { alert("Invalid Image URL: " + url ); }
		}
	else { alert("Invalid URL: " + url ); }
	}
else { if ( url == "" ) alert("No URL Entered"); }
 
/////////////////////////
// FUNCTIONS
/////////////////////////
function placeSmartObject(fileRef){
	//create a new smart object  layer using a file
	try { 
		var desc = new ActionDescriptor();
			desc.putPath( charIDToTypeID( "null" ), new File( fileRef ) );
			desc.putEnumerated( charIDToTypeID( "FTcs" ), charIDToTypeID( "QCSt" ),charIDToTypeID( "Qcsa" ));
			desc.putUnitDouble( charIDToTypeID( "Wdth" ),charIDToTypeID( "#Prc" ), 100 );
			desc.putUnitDouble( charIDToTypeID( "Hght" ), charIDToTypeID( "#Prc" ), 100 );
			desc.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), 0 );
			desc.putBoolean( charIDToTypeID( "Lnkd" ), true );
		executeAction( charIDToTypeID( "Plc " ), desc, DialogModes.NO );
		activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);
		activeDocument.revealAll();
	} catch (e) { alert("Placeing file: '" + fileRef + "' failed"); }
};

// Remove header lines from HTTP response
function removeHeaders(binary){
	var bContinue = true ; // flag for finding end of header
	var line = "";
	var httpheader = "";
	var nFirst = 0;
	var count = 0;
	while (bContinue) {
		line = getLine(binary) ; // each header line
		httpheader = httpheader + line;
		bContinue = line.length >= 2 ; // blank header == end of header
		nFirst = line.length + 1 ;
		binary = binary.substr(nFirst) ;
	}
	if (httpheader.indexOf("Bad Request") != -1 || httpheader.indexOf("Not Found") != -1) {
		alert (requesthtml + request + httpheader);
		var binary = "";
	}
	//alert (requesthtml + request + httpheader + "\nFile length = " + binary.length);
	return binary;
};
 
// Get a response line from the HTML
function getLine(html){
	var line = "" ;
	for (var i = 0; html.charCodeAt(i) != 10; i++){ // finding line end
		line += html[i] ;
	}
	return line ;
};

 

JJMack

Votes

Translate

Translate

Report

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
Explorer ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

soooo much friend it worked in 2021: D

Votes

Translate

Translate

Report

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
Explorer ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

What if the image is PSD? is it possible to open it also making some modification in the code?

Votes

Translate

Translate

Report

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

The code does not seem to work on my machine these days.... I have not look at why it is not.

JJMack

Votes

Translate

Translate

Report

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
Explorer ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

Thanks friend, now I have the idea of using this code base to open a javascript in Photoshop ... is that possible? I will make a new post about: D Thanks again

Votes

Translate

Translate

Report

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 ,
Jan 12, 2021 Jan 12, 2021

Copy link to clipboard

Copied

LATEST

There have been many changes to HTML and web server security and protocol since the script was written. When I use that script with the url you posted the script just gets a header.  Yet my browser has no trouble with the url.  The script just gets so the script heeds to be updated to use the correct protocol for HTTPS. When the script failed the work with https://  URL I striped the s  because the script uses HTTP/1.0 server protocol.  I know noting whet it comes to web server  interfaces. Sometime the seem toworm

image.png

 

JJMack

Votes

Translate

Translate

Report

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