This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2010-12-09 15:00:06

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

exporting images and creating folders in squeak?

Hey all. What smalltalk command would I use to export a costume to a file directory on my computer as an image file? Is there a smalltalk command for creating a folder?
Thanks!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2010-12-09 15:03:18

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

indeed there is. i cannot look it up for you right now, but Bingo uses that to export images from the paint editor (note the new little [export] button) and also has a
write [image] to file []
block which you could take the code from. it's not too hard, Scratch implemented a whole GIF and BMP read/writer.

Offline

 

#3 2010-12-09 15:04:10

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: exporting images and creating folders in squeak?

I tried self exportMedia: t1 toFile: t2 with no luck.... same with exportCostume: t1 toFile: t2


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2010-12-09 15:05:35

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

sparks wrote:

I tried self exportMedia: t1 toFile: t2 with no luck.... same with exportCostume: t1 toFile: t2

ok, hold on while i go check in bingo. it's not that easy  hmm

-
At least 60 seconds have to pass between posts. Please wait a little while and try posting again.

Offline

 

#5 2010-12-09 15:13:34

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

pic exportFilename: fn for: self
that's the code taken exactly from the block.

ImageMedia new form: formName; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName).
that's the code for creating an image media from a form. except, youll have to replace formName with the variable representing the form.

hope this helps  big_smile

Offline

 

#6 2010-12-09 15:16:14

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

a code snippet would be

Code:

thepic _ ImageMedia new form: FORMNAME; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName).

thepic exportFilename: 'c:\pic.gif' for: self.

Offline

 

#7 2010-12-09 15:26:26

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: exporting images and creating folders in squeak?

This is my code:

Code:

|thepic|
thepic _ ImageMedia new form: t1 asString; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName).

thepic exportFilename: t2  for: self.

... It does not work  sad


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#8 2010-12-09 15:28:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

sparks wrote:

This is my code:

Code:

|thepic|
thepic _ ImageMedia new form: t1 asString; mediaName: (self unusedMediaNameFromBaseName: self defaultImageMedia mediaName).

thepic exportFilename: t2  for: self.

... It does not work  sad

that t1 asString doesn't look right.
is t1 supposed to be a form variable or a ScratchSkin member?
if it's the first option, take the asString away  smile

Offline

 

#9 2010-12-09 15:38:27

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: exporting images and creating folders in squeak?

t1 is a number (costume number) of the sprite, and in my experience squeak does not like working with number arguments, so the asString turns it into a string that squeak usually likes to work with. It does not work without the asString either.


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#10 2010-12-09 15:51:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: exporting images and creating folders in squeak?

sparks wrote:

t1 is a number (costume number) of the sprite, and in my experience squeak does not like working with number arguments, so the asString turns it into a string that squeak usually likes to work with. It does not work without the asString either.

that explains it. you will need some extra code in place of the t1 to actually retrieve the ImageMedia of that number. Sorry but I can't help you right now as it's pretty late here and I'm about to doze off on the keyboard. Good luck!  big_smile

Offline

 

#11 2010-12-18 15:42:42

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: exporting images and creating folders in squeak?

bump? I'd love to get this block working! (not only can I add it to my block library, it will let me make some nice changes very easily!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#12 2010-12-18 16:27:45

MathWizz
Scratcher
Registered: 2009-08-31
Posts: 1000+

Re: exporting images and creating folders in squeak?

Lets see... *opens Scratch*
This should do it!

Code:

exportCostume: t1 toFile: t2 
    | t3 t4 t5 |
    t3 _ nil.
    (t1 isKindOf: String)
        ifTrue: 
            [t3 _ self costumeFromName: t1.
            t3
                ifNil: 
                    [t4 _ self interpretStringAsNumberIfPossible: t1.
                    t4 isNumber
                        ifTrue: [t3 _ self costumeFromName: (self costumeNameFromNumber: t4)]
                        ifFalse: [^ self]]].
    t3
        ifNil: 
            [t4 _ t1 asNumberNoError.
            t3 _ self costumeFromName: (self costumeNameFromNumber: t4)].
    t3 ifNil: [^ self].
    t5 _ t2.
    (t5 endsWith: '.png')
        ifFalse: [t5 _ t5 , '.png'].
    t3 form writePNGFileNamed: t5

http://block.site90.net/scratch.mit/text.php?size=30&text=%20A%20signature!&color=333333

Offline

 

#13 2010-12-19 04:32:31

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: exporting images and creating folders in squeak?

Thanks that's pretty awesome!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

Board footer