Copy link to clipboard
Copied
Hi,
We have a PHP and MYSQL system which generates a JSX file for design.
It pulls one value out of the database and via php to the jsx file.
We have an issue with some characters which are set in the UTF8 charset, which are correctly displayed in the database and in PHP and HTML.
But when set in photoshop code, it causes issues and displays them incorrectly.
For example
activeDocument.activeLayer.textItem.contents="""' . $rs_item['slogan_name'] . '""";
Du ser mig kun for det tøj jeg har på
This displays correctly in php, mysql etc, but when set in photoshop it displays to:
Du ser mig kun for det tøj jeg har på
Is there a way to set a charset for a value for photoshop?
I tried
activeDocument.activeLayer.textItem.encoding = "UTF8";
but i dont think there is such a value for textitem?
Thanks
You here gave an example of your PHP script.
...if($_SESSION['admin_name']!=="Admin") {
// CLOSE THE TEMPLATE PSD AND OPEN THE ACTUAL DESIGN IN PSD
$design_code .= '
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
var fileRef = "' . "/z/DESIGN_SERVER/" . $savefilename . ".psd" . '";
app.open( new File( fileRef ) );
';
} else {
// CLOSE THE TEMPLATE PSD AND OPEN THE ACTUAL DESIGN PDF
$design_code .= '
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
var fileRef =
Copy link to clipboard
Copied
I do not understand.
In Photoshop, your code gives this text in the layer
Show the real code that is executed in Photoshop. (jsx file)
Copy link to clipboard
Copied
Hi, no sorry that is PHP code. That is selecting a php $ value. see original post for the 2 values
Copy link to clipboard
Copied
Photoshop does not execute PHP scripts as far as I know.
How do you make a photoshop perform its native scripting code. That's what interests me.
Most likely there is an encoding error
Copy link to clipboard
Copied
Hi,
We have a PHP file which generates lots of Photoshop lines of code and ends up with a full script.
It uses the php value $design_code .= '
And complies set jsx files up to 100-200 files long to design many features based on customers requirements.
So the PHP compiles the JSX code and executes it.
We have been working on it for several weeks and it has been working fantastically.
My question is purely about charsets and why when the script puts the contents in, vs copy and paste why it displays different.
Our processing is irrelevant to the question.
I am surprised that no one else is using PHP to compile JSX scripts.
Forget the $value, see the contents i wrote as an example.
Is there no charset setting in photoshop for contents?
Copy link to clipboard
Copied
Here is an example of one piece of our script in php
if($_SESSION['admin_name']!=="Admin") {
// CLOSE THE TEMPLATE PSD AND OPEN THE ACTUAL DESIGN IN PSD
$design_code .= '
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
var fileRef = "' . "/z/DESIGN_SERVER/" . $savefilename . ".psd" . '";
app.open( new File( fileRef ) );
';
} else {
// CLOSE THE TEMPLATE PSD AND OPEN THE ACTUAL DESIGN PDF
$design_code .= '
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
var fileRef = "' . "/z/DESIGN_SERVER/" . $savefilename . ".pdf" . '";
app.open( new File( fileRef ) );
';
}
You will see there is an IF THEN ELSE php statement which looks to see if the session admin_name = Admin
If it doesit will add JSX photoshop script lines to the $design_code value.
In this instance it is basically stating if the session value is Admin open the psd, whereas if it isnt admin, open the pdf version.
And so on, at the end of the PHP code we end up with a complied jsx file which is executed from the $design_code variable.
So for example when you are seeing the ' . this is simply coming out of the variable $design_code and sourcing the parameter in PHP in this case a value $saveflename which has been declared earlier in php code.
Regarding my question we have noticed differences between us setting text via .contents vs pasting in photoshop hence we were wondering if there was some sort of a charset mismatch in code vs pasting directly in to photoshop.
Copy link to clipboard
Copied
Most likely, Photoshop does not understand the encoding of your code or the file that you send to it.
A simple example is two jsx files without BOM (Byte Order Mark) for UTF8.
alert("Du ser mig kun for det tøj jeg har på")
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
// 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
alert("Du ser mig kun for det tøj jeg har på")
In a short file, Photoshop correctly defines the encoding of UTF8. But in the second, where the first text is a simple text, the photoshop defines it as a system encoding such as CP1252 or similar.
Accordingly, the first file at execution gives
A long file, with the same key code, gives something like this
I do not know PHP at all, but I'll try to advise you to insert such a code
$ design_code. = '\xEF\xBB\xBF
// here comes your old code
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Did you download and run the script_bad.jsx script or created it yourself via copy-paste? Works with an error in CC2018.1.4 and in CS6. All on Windows 7 x64 and x86.
Copy link to clipboard
Copied
Hi,
I copy-pasted your code and ran it from the ESTK. No error.
Saved the pasted code and ran it from PhotoShop and also InDesign. No error.
Downloaded your script_bad.jsx, opened it in the ESTK and ran it. No error.
Well, now that you answered:
Downloaded your script_bad.jsx, did not open and did not save it in the ESTK.
Ran it from PhotoShop, ran it from InDesign:
Now I can see the error.
Regards,
Uwe
Copy link to clipboard
Copied
We are also having issues with hyphens ' putting ’ so it is a charset issues, but we have the correct charsets set on database connections, html and php page.
Copy link to clipboard
Copied
This one doesnt work notice the character is
’
activeDocument.activeLayer.textItem.contents="It’s";
but this does work
activeDocument.activeLayer.textItem.contents="It's";
note the character is
'
We have done a simple str_replace in php which will replace the first example for second.
But copy and pasting works fine for the first example, but doesnt in script and shows:
’
Also reference similar issues post
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I tried that but it made no difference. I am on CS6
Copy link to clipboard
Copied
I tried that but it made no difference. I am on CS6
But it works in CS6.
activeDocument.activeLayer.textItem.contents="It’'s";
Show your full code.
Or specify what it does not work.
Copy link to clipboard
Copied
Ok it seems something else in our code is causing this. And end file is about 150-200 lines long, when we run just part of the code its fine, but with all the code it happens, so there must be something in the code causing it. Will do some more testing and come back thanks.
Copy link to clipboard
Copied
Have you tried to insert the UTF8 BOM marker at the beginning of your code ($design_code) as I suggested?
Copy link to clipboard
Copied
Hi sorry didnt see this reply. Yes i added the UTF8 BOM marker at the start of the JSX file but it didnt work, see below.
I am still having issues with several characters another one is this one • showing as •
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
- // 111111111111111111111111111111111111111111111111111111111111111111111111111111111111
Copy link to clipboard
Copied
I did not understand what you wrote above.
Well, I do not know.
You, like, wrote that with a short code you are all right.
Then try at the very beginning of your sample long code to paste something like
var dummy_utf8 = "Du ser mig kun for det tøj jeg har på";
Copy link to clipboard
Copied
Hi can you confirm the correct code to add please for UTF8 BOM marker as those // 1111 is what you sent?
Copy link to clipboard
Copied
I do not understand you at all. UTF8 BOM is three characters, a string of three bytes,
"\xEF\xBB\xBF"
or
String.fromCharCode (0xEF, 0xBB, 0xBF).
Try to google this question.
for example utf 8 - Encoding a string as UTF-8 with BOM in PHP - Stack Overflow
Copy link to clipboard
Copied
Hi,
Php is correctly formatting the text.
I have checked JSX files and its labelled correctly.
for example:
activeDocument.activeLayer.textItem.contents="""Tiocfiadh ár lá""";
So this JSX file has the above, which means PHP has correctly saved the correct text in the JSX file.
But when the JSX file is exceuted, it then shows
Tiocfiadh ár lá
in photoshop, so its something in photoshop charset causing it vs php.
Regarding the 111 code, you posted this back on 04-Jul-2018 03:43 i have no idea what it is but thought it was to do with BOM
Copy link to clipboard
Copied
Put here a link to your "allegedly" correct jsx file. I'll see if it has UTF8 BOM
Copy link to clipboard
Copied
Will send as PM.
Copy link to clipboard
Copied
Will send as PM.
You sent a copy-pasted text of the script where there are UTF-8 characters.
I do not need the text of the script. I need a specific jsx file, which is generated by your PHP script, and which you send the photoshop on for execution. I need a link to your file, not the text itself in this file.