Image.st
changeset 7173 075306bcac68
parent 7156 97b4f12aa796
child 7175 4bd37cf4075e
--- a/Image.st	Wed Mar 02 14:13:50 2016 +0100
+++ b/Image.st	Wed Mar 02 14:14:17 2016 +0100
@@ -14061,24 +14061,7 @@
      (see ImageReader subclasses implementing save:onFile:).
      May raise a signal, if the image cannot be written by the reader."
 
-    |suffix readerClass|
-
-    "/
-    "/ from the extension, get the imageReader class
-    "/ (which should know how to write images as well)
-    "/
-    suffix := aFileName asFilename suffix.
-    readerClass := MIMETypes imageReaderForSuffix:suffix.
-    readerClass notNil ifTrue:[
-        ^ self saveOn:aFileName using:readerClass
-    ].
-
-    "/
-    "/ no known extension - could ask user for the format here.
-    "/ currently default to tiff format.
-    "/
-    'Image [warning]: unknown extension - cannot figure out format - using default (tiff)' errorPrintCR.
-    ^ self saveOn:aFileName using:(self class defaultImageFileWriter)
+    ^ self saveOn:aFileName quality:nil
 
     "
      |image|
@@ -14093,12 +14076,50 @@
     "Modified: 30.6.1997 / 22:06:34 / cg"
 !
 
-saveOn:aFileName using:readerClass
+saveOn:aFileName quality:qualityPercentOrNil
+    "save the image in aFileName. The suffix of the filename controls the format.
+     Currently, not all formats may be supported
+     (see ImageReader subclasses implementing save:onFile:).
+     May raise a signal, if the image cannot be written by the reader."
+
+    |suffix readerClass|
+
+    "/
+    "/ from the extension, get the imageReader class
+    "/ (which should know how to write images as well)
+    "/
+    suffix := aFileName asFilename suffix.
+    readerClass := MIMETypes imageReaderForSuffix:suffix.
+    readerClass isNil ifTrue:[        
+        "/
+        "/ no known extension - could ask user for the format here.
+        "/ currently default to tiff format.
+        "/
+        readerClass := self class defaultImageFileWriter.
+        'Image [warning]: unknown extension - cannot figure out format - using default (',readerClass name,')' errorPrintCR.
+    ].
+    ^ self saveOn:aFileName quality:qualityPercentOrNil using:readerClass
+
+
+    "
+     |image|
+
+     image := Image fromFile:'goodies/bitmaps/RCube.tiff'.
+     image saveOn:'myImage.tiff'.
+     image saveOn:'myImage.xbm'.
+     image saveOn:'myImage.xpm'.
+     image saveOn:'myImage.xwd'.
+    "
+
+    "Modified: 30.6.1997 / 22:06:34 / cg"
+!
+
+saveOn:aFileName quality:qualityPercentOrNil using:readerClass
     "save the receiver using the representation class
      (which is usually a concrete subclasses of ImageReader).
      May raise a signal, if the image cannot be written by the reader."
 
-    ^ readerClass save:self onFile:aFileName
+    ^ readerClass save:self onFile:aFileName quality:qualityPercentOrNil
 
     "
      |anImage|
@@ -14119,9 +14140,61 @@
 
      anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
      Image cannotRepresentImageSignal handle:[:ex |
-	self warn:'cannot save the image in this format'
+        self warn:'cannot save the image in this format'
      ] do:[
-	anImage saveOn:'myImage.xbm' using:XBMReader.
+        anImage saveOn:'myImage.xbm' using:XBMReader.
+     ]
+    "
+
+    "
+     |anImage|
+
+     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
+     anImage saveOn:'myImage.xpm' using:XPMReader.
+    "
+
+    "
+     |anImage|
+
+     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
+     anImage saveOn:'myImage.gif' using:GIFReader.
+    "
+
+    "Modified: 10.4.1997 / 17:49:26 / cg"
+!
+
+saveOn:aFileName using:readerClass
+    "save the receiver using the representation class
+     (which is usually a concrete subclasses of ImageReader).
+     May raise a signal, if the image cannot be written by the reader."
+
+    ^ readerClass save:self onFile:aFileName quality:nil
+
+    "
+     |anImage|
+
+     anImage := Image fromFile:'../../goodies/bitmaps/gifImages/garfield.gif'.
+     anImage saveOn:'myImage.tiff' using:TIFFReader.
+     (Depth24Image fromImage:anImage) saveOn:'myImage.jpg' using:JPEGReader.
+     anImage saveOn:'myImage50.tiff' quality:50 using:TIFFReader.
+     (Depth24Image fromImage:anImage) saveOn:'myImage50.jpg' quality:50 using:JPEGReader.
+    "
+
+    "
+     |anImage|
+
+     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
+     anImage saveOn:'myImage.xbm' using:XBMReader.
+    "
+
+    "
+     |anImage|
+
+     anImage := Image fromFile:'goodies/bitmaps/gifImages/garfield.gif'.
+     Image cannotRepresentImageSignal handle:[:ex |
+        self warn:'cannot save the image in this format'
+     ] do:[
+        anImage saveOn:'myImage.xbm' using:XBMReader.
      ]
     "