ハードディスクに保存したjpgファイルなどをスタックに読み込むには、answer file "Select a folder
for the image:"などでitにファイルディレクトリを入れ、次の一行を実行することでできます。
import paint from file it
|
このようにして読み込んだ画像ファイルは、現在開いているカードにペーストされ、大きさは当然元の画像ファイルの大きさです。
読み込んだ画像ファイルの縦横の大きさを変えるには、
set the width of img ImageName
to 64
set the height of img ImageName to
32
set the lockLocation of img ImageName
to true
|
などで出来ますが、これは見かけ上の大きさを変えただけで、実データサイズは変更されません。もし、この画像をサムネイル画像などとして利用すると、不必要に大きな画像データをスタックで使用することになります。
画像の実データサイズをサムネイル用に縮小するには次のスクリプトが有効です。BBSのオリジナル英文を添付しておきます。
set the width of img ImageName
to 64
set the height of img ImageName to
32
set the lockLocation of img ImageName
to true
create image ResizedImage
set the width of img ResizedImage to
the width of img ImageName
set the height of img ResizedImage
to the height of img ImageName
set the imagedata of img ResizedImage
to the imagedata of img ImageName
delete img ImageName
|
解説:
ImageNameは、スタックに読み込んだオリジナルの画像データです。(とても大きい)
最初の二行で、これを見かけ上、最終的に縮小した時の大きさにします。(この場合、64 X 32ピクセルにしています。)
三行目で、 lockLocationをtrueにします。
このようにして縮小した画像データは、見かけ上は縮小されていますが、実データサイズは変更されていません。四行目以下のスクリプトで、実データサイズを縮小します。
四行目で、ResizedImageという新規のイメージを作り、五〜六行目で、その新規イメージの縦横のサイズを縮小したImageNameの縦横とまったく同じにします
(重要)。
このようにして出来た ResizedImageにImageNameの画像を
set the imagedataでコピーすると、アラ不思議、画像のデータサイズが縮小された画像がResizedImageに出来ます。
最後の行で不要になったオリジナル画像のデータを削除しています。
Hallo Claus,
> Hi,
>
> I'm looking for an elegant way to resize (shrink) an image.
>
> Changing the width and the height only affects the display.
> Saving this image to file results in the original image with the
> original size.
> So this won't do.
>
> Has anyone an elegant way to save a thumnail of an image?
There are probably 2 (or more ;-) ways to do this...
1. Use Trevors excellent QT External to create a preview image of ANY
size...
2. Built-in solution: no external required :-)
Size your original image as you like (lock loc!)
Create a new image and script:
...
set the width of img "the new one" to the widht of img "the
original
one"
set the height of img "the new one" to the heigth of img "the
original
one"
set the imagedata of img "the new one" to the imagedata of
img "the
original one"
...
Now you have a new image that you can export as jpg or do whatever you
want with :-)
Hope that helps...
> Regards,
> Claus.
>
> PS: Let's see who as nothing better to do on a sunday than reading
> this list ;-)
ME! :-)
(But the Revolution knows NO weekend!)
Regards (und liebe Gruse :-)
|