# Using ruby with photoshop - p objectroblem using the SaveAs

**URL:** <https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052>\
**Category:** Ruby\
**Created:** [October 29, 2006, 3:33pm UTC](https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052 "2006-10-29T15:33:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [October 29, 2006, 3:33pm UTC](https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052/1 "2006-10-29T15:33:03Z")

</div>

# help

I have been trying to get a COM connection to work from ruby to  
photoshop

Everything works fine until I try and save my image, I cant get the  
right  
syntax for the SaveAs function to work. I’ve tried reference both the  
JavaScript and VB guides for clues but cant get any thing to work

Here is what I’m using at the moment, cant find anything on the net  
dealing  
with ruby and photoshop, so I was wondering if any one out there might  
have  
got it working that is the SaveAs object

require ‘win32ole’

cs = WIN32OLE.new(“Photoshop.Application”)

jpgopt = WIN32OLE.new(“Photoshop.JPEGSaveOptions”)

jpgopt.Quality = 12

jpgopt.FormatOptions = 3

jpgopt.Matte= 1

jpgopt.Scans = 5

cs.DisplayDialogs = 3 # No dialog when open the raw file.

textColor = cs.ForegroundColor

textColor.RGB.Red = 255

textColor.RGB.Green = 0

textColor.RGB.Blue = 0

docRef = cs.Documents.Add(300, 200, 72,“My New Document”);

newTextLayer = docRef.ArtLayers.Add();

newTextLayer.Kind = 2;

newTextLayer.TextItem.Contents = “Hello, World!”;

newTextLayer.TextItem.Position = [100, 100];

newTextLayer.TextItem.Size = 16;

newTextLayer.TextItem.Color = textColor;

saveme = ActiveDocument

saveme.SaveAs(‘C:/cells2.jpg’, jpgopt, true, Extension.LOWERCASE);

docRef.Close(2)

```
   help
```

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [November 7, 2006, 10:46am UTC](https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052/2 "2006-11-07T10:46:12Z")

</div>

On 10/29/06, Martin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> saveme = ActiveDocument

That should be:  
saveme = cs.ActiveDocument

> saveme.SaveAs(‘C:/cells2.jpg’, jpgopt, true, Extension.LOWERCASE);

I don’t know about Extension here, it gave me an error, so I just  
removed that last part, and it seemed to work:

saveme.SaveAs(‘C:/cells2.jpg’, jpgopt, true);

CT

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [November 7, 2006, 10:47am UTC](https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052/3 "2006-11-07T10:47:07Z")

</div>

What verisons are you using, I’m still getting an illegal argument -  
argument 1  
Required values is missing

---

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [November 7, 2006, 10:47am UTC](https://www.ruby-forum.com/t/using-ruby-with-photoshop-p-objectroblem-using-the-saveas/74052/4 "2006-11-07T10:47:16Z")

</div>

On 10/30/06, Martin S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> What verisons are you using, I’m still getting an illegal argument -  
> argument 1  
> Required values is missing

WinXP Pro SP2, Photoshop CS (8.0). Works here! :}

Have you seen this?

> **[PhotoshopScriptingGuide.pdf](https://partners.adobe.com/public/developer/en/photoshop/sdk/PhotoshopScriptingGuide.pdf)**

On page 50 they have examples of SaveAs (in VBS and JS). It looks  
like the last value you were passing (Extension.LOWERCASE) would be an  
int (2 == for lowercase).

HIH

CT
