photoshop - export file simultaeously in multiple jpeg qualities or file formats - export

In photoshop I need to export files in both 100% and 10%. is there a simple way i can do this in one go instead of having to do this twice? thanks

Let's assume you're talking about jpeg quality.
With a bit of digging you can find a function to save as an image as jpg.
// Path to the two images, named appropriately
// NOTE change to suit your needs
var myFileA = "C:\\myfolder\\myjpeg_high_quality.jpg";
var myFileB = "C:\\myfolder\\myjpeg_low_quality.jpg";
// Jpeg quality used to be from 1-10 in the old days.
// Now it's from 1-12, Let's save out the best and the worst.
jpeg_it(myFileA, 12);
jpeg_it(myFileB, 1);
// function JPEG IT (file path + file name, quality)
// ----------------------------------------------------------------
function jpeg_it(filePath, jpgQuality)
{
if(! jpgQuality) jpgQuality = 12;
// jpg file options
var jpgFile = new File(filePath);
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.formatOptions = FormatOptions.OPTIMIZEDBASELINE;
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpgQuality;
activeDocument.saveAs(jpgFile, jpgSaveOptions, true, Extension.LOWERCASE);
}

Related

How to edit text files with google apps script? It must be done with Drive Advanced Api [duplicate]

I want Google script variable data into Google drive as text file and update that text file regulatory via Google script!
The following code creates a text file and writes the data on it.I wonder how i can update the text file later ?
function createTextFile()
{
name="testFile.txt";
name2="testFolder";
var content = "this is text data to be written in text file";
var dir = DriveApp.getFoldersByName(name2).next()
var file = dir.createFile(name, content);
}
Just in case anyone's still interested 3 years later... :)
The following will create or append, assuming content is text:
function createOrAppendFile() {
var fileName="myfile";
var folderName="myfolder";
var content = "this is text data to be written in text file";
// get list of folders with matching name
var folderList = DriveApp.getFoldersByName(folderName);
if (folderList.hasNext()) {
// found matching folder
var folder = folderList.next();
// search for files with matching name
var fileList = folder.getFilesByName(fileName);
if (fileList.hasNext()) {
// found matching file - append text
var file = fileList.next();
var combinedContent = file.getBlob().getDataAsString() + content;
file.setContent(combinedContent);
}
else {
// file not found - create new
folder.createFile(fileName, content);
}
}
}
In summary, as there appears to be no append function, you instead simply read the existing file contents, add the new content, then (over)write the combined content back to the file.
*tip - add a "\n" between the old and new content for a new line separator
update Override the contents if the file is exists.
function saveData(folder, fileName, contents) {
var filename = "testFile.txt";
var children = folder.getFilesByName(filename);
var file = null;
if (children.hasNext()) {
file = children.next();
file.setContent(contents);
} else {
file = folder.createFile(filename, contents);
}
}
function test() {
var folders = DriveApp.getFoldersByName("testFolder");
if (folders.hasNext()) {
var folder = folders.next();
saveData(folder, "testfile.txt", "HelloWorld");
saveData(folder, "testfile.txt", "Welcome");
}
}

Copy File Into Good Folder

I want to code a function who copy my files of one specific folder into another folder who have some specifics folders creates with another function with the descriptions of my files.
So into my while loop filesIter.hasNext() to check the description of all my files I need to implement an other while folderIter.hasNext() to check the description of my folders. And if the two descriptions are equal, I copy the file into the good folder.
But for the moment I can do it just into my first Folder but I don't know how I can check the next folder while the description of my file not equal to the description of my folder.
function CopySheetsIntoGoodFolder2() {
var folderFiles = DriveApp.getFolderById('123C');
var filesIter = folderFiles.getFiles();
while (filesIter.hasNext()) {
var files = filesIter.next();
var descriFiles = files.getDescription();
var folder = DriveApp.getFolderById('123D');
var folderIter = folder.getFolders();
var folders = folderIter.next();
var descriFolder = folders.getDescription();
while (descriFiles != descriFolder) {
folderIter.hasNext().next();
}
if (descriFiles == descriFolder) {
files.makeCopy(folders);
}
}
}
I know that is my second while who is wrong but I don't know how to do what I want. I've tried so much things but now i'm blocked...
You need an outer loop to get the file descriptions. And an inner loop (inside the outer loop) to get the folder descriptions and match them to the file descriptions.
Try this:
function CopySheetsIntoGoodFolder2() {
var folderFiles = DriveApp.getFolderById('123C');
var filesIter = folderFiles.getFiles();
// This can be outside the loop. No point getting the same folder each time
var folder = DriveApp.getFolderById('123D');
// Declare variable
var files, folders, descriFiles, descriFolder, folderIter;
// Loop through files [Outer loop]
while (filesIter.hasNext()) {
files = filesIter.next(); // The file
descriFiles = files.getDescription(); // File description
folderIter = folder.getFolders(); // Get sub-folders
while (folderIter.hasNext()) { // Loop through sub-folders [Inner loop]
folders = folderIter.next(); // Get a folder
descriFolder = folders.getDescription(); // Get its description
if (descriFiles == descriFolder) { // Check is descriptions match
files.makeCopy(folders);
break; // Break loop if the descriptions match and the file has been copied.
}
}
}
}

how to concate multiple (mp4 format) video into one video(mp4 format) in c#

I'm writing a program Which will concat multiple (mp4 format) to one file.But Problem is that my code only show last video file in merged file(m.mp4).The code which I am using is given below for description.
FileStream fs = new FileStream("m.mp4",FileMode.Append);
for (i = 1; i <= 3; i++)
{
//m1,m2,m3 are video mp4 files on my disk
var bytes = File.ReadAllBytes("m" + i + ".mp4");
fs.Write(bytes, 0, bytes.Length);
}
Console.WriteLine("Done!!");

What is a compact way to save a float32array to disk on node.js?

JSON.stringify is obviously not space-efficient. What is the most elegant way to serialize and store a float32array using Node.js?
EDIT: People are closing the question for reasons such as being "opinion based" and "lack of an understanding of the problem". I seriously believe the first one was a missclick. For the second one, maybe this makes it more clear:
var fs = require("fs");
var len = 1000*1000*10;
var big_array = new Float32Array(len);
for (var i=0; i<len; ++i)
big_array[i] = Math.random();
// OBVIOUSLY NOT SPACE EFFICIENT \/
fs.writeFileSync("big_array.json",JSON.stringify(big_array));
It is not space efficient because you are representing numbers as strings, so an 8 bytes float will be using as much as ~20 utf8 chars, which is a waste. The question is: how to store the array in a space-efficient manner?
Finally I managed to write float32array to disk with nodejs and retrieve them on the browser, and I hope it will help you.
Write Float32Array to binary file in NodeJS
var fs = require('fs');
var wstream = fs.createWriteStream('data.dat');
var data = new Float32Array([1.1,2.2,3.3,4.4,5.5]);
//prepare the length of the buffer to 4 bytes per float
var buffer = new Buffer(data.length*4);
for(var i = 0; i < data.length; i++){
//write the float in Little-Endian and move the offset
buffer.writeFloatLE(data[i], i*4);
}
wstream.write(buffer);
wstream.end();
Read the file and convert it to a Float32Array on a Browser
var urlToFloatFile = 'data.dat';
var request = new XMLHttpRequest();
request.open('GET', urlToFloatFile, true);
//specify the response type as arraybuffer
request.responseType = 'arraybuffer';
request.onload = function (msg) {
var yourFloatData = new Float32Array(this.response);
console.log(yourFloatData);
};
request.send();
Thanks to #ben_a_adams from WebGL Dev List GGroup https://groups.google.com/forum/#!topic/webgl-dev-list/EbGUi_iSEx8 for the client side code
I've create a simple test to test roughly how much space a JSON serialization of a float array differs from a binary representation and the results are:
2.000.000 floating point values
7.8MB on a binary file
38.5MB on a JSON file
17.5 on a Gzipped JSON file
There is actually a much simpler version possible
let fs = require('fs')
let data = [150, 180]
fs.writeFileSync('mydata', new Buffer(new Uint32Array(data).buffer))
fs.readFile('mydata', (err, buf) => {
let restoredData = new Uint32Array(buf.buffer, buf.offset, buf.byteLength/4)
console.log(data[1])
console.log(restoredData[1])
});
Easy, clean way to do it:
const float32Array = new Float32Array([.69,.420])
const buffer = Buffer.from(float32Array.buffer)
fs.writeFileSync(filePath, buffer)
const loadedBuffer = fs.readFileSync(filePath)
const newFloat32Array = new Float32Array(loadedBuffer.buffer)
I believe you could use Meteor's EJSON:
http://docs.meteor.com/#ejson
https://npmjs.org/package/meteor-ejson
EJSON is an extension of JSON to support more types. It supports all
JSON-safe types, as well as:
Date (JavaScript Date)
Binary (JavaScript Uint8Array or the result of EJSON.newBinary)
User-defined types (see EJSON.addType. For example, Meteor.Collection.ObjectID is implemented this way.)

Image Analysis Program Based on Hashcode Method Resulting in Errors

I am trying to write a program that will recognize an image on the screen, compare it against a resource library, and then calculate based on the result of the image source.
The first thing that I did was to create the capture screen function which looks like this:
private Bitmap Screenshot()
{
System.Drawing.Bitmap Table = new System.Drawing.Bitmap(88, 40, PixelFormat.Format32bppArgb);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(RouletteTable);
g.CopyFromScreen(1047, 44, 0, 0, Screen.PrimaryScreen.Bounds.Size);
return Table;
}
Then, I analyze this picture. The first method I used was to create two for loops and analyze both the bitmaps pixel by pixel. The problem with this method was time, it took a long time to complete 37 times. I looked around and found the convert to bytes and the convert to hash methods. This is the result:
public enum CompareResult
{
ciCompareOk,
ciPixelMismatch,
ciSizeMismatch
};
public CompareResult Compare(Bitmap bmp1, Bitmap bmp2)
{
CompareResult cr = CompareResult.ciCompareOk;
//Test to see if we have the same size of image
if (bmp1.Size != bmp2.Size)
{
cr = CompareResult.ciSizeMismatch;
}
else
{
//Convert each image to a byte array
System.Drawing.ImageConverter ic = new System.Drawing.ImageConverter();
byte[] btImage1 = new byte[1];
btImage1 = (byte[])ic.ConvertTo(bmp1, btImage1.GetType());
byte[] btImage2 = new byte[1];
btImage2 = (byte[])ic.ConvertTo(bmp2, btImage2.GetType());
//Compute a hash for each image
SHA256Managed shaM = new SHA256Managed();
byte[] hash1 = shaM.ComputeHash(btImage1);
byte[] hash2 = shaM.ComputeHash(btImage2);
for (int i = 0; i < hash1.Length && i < hash2.Length&& cr == CompareResult.ciCompareOk; i++)
{
if (hash1[i] != hash2[i])
cr = CompareResult.ciPixelMismatch;
}
}
return cr;
}
After I analyze the two bitmaps in this function, I call it in my main form with the following:
Bitmap Table = Screenshot();
CompareResult success0 = Compare(Properties.Resources.Result0, Table);
if (success0 == CompareResult.ciCompareOk)
{ double result = 0; Num.Text = result.ToString(); goto end; }
The problem I am getting is that once this has all been accomplished, I am always getting a cr value of ciPixelMismatch. I cannot get the images to match, even though the images are identical.
To give you a bit more background on the two bitmaps, they are approximately 88 by 40 pixels, and located at 1047, 44 on the screen. I wrote a part of the program to automatically take a picture of that area so I did not have to worry about the wrong location or size being captured:
Table.Save("table.bmp");
After I took the picture and saved it, I moved it from the bin folder in the project directly to the resource folder and ran the program again. Despite all of this, the result is still ciPixelMismatch. I believe the problem lies within the format that the pictures are being saved as. I believe that despite them being the same image, they are being analyzed in different formats, maybe one of the pictures contains a bit more information than the other which is causing the mismatch. Can somebody please help me solve this problem? I am just beginning with my c# programming, I am 5 days into the learning process, and I am really at a loss for this.
Yours sincerely,
Samuel

Resources