| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -55,12 +55,10 @@ export function testSaveToFile() { | |||
| 55 | 55 | } | |
| 56 | 56 | ||
| 57 | 57 | export function testSaveToFile_WithQuality() { | |
| 58 | - // >> imagesource-save-to | ||
| 59 | 58 | const img = imageSource.fromFile(imagePath); | |
| 60 | 59 | const folder = fs.knownFolders.documents(); | |
| 61 | 60 | const path = fs.path.join(folder.path, "test.png"); | |
| 62 | 61 | const saved = img.saveToFile(path, "png", 70); | |
| 63 | - // << imagesource-save-to | ||
| 64 | 62 | TKUnit.assert(saved, "Image not saved to file"); | |
| 65 | 63 | TKUnit.assert(fs.File.exists(path), "Image not saved to file"); | |
| 66 | 64 | } | |
@@ -199,11 +197,8 @@ export function testBase64Encode_PNG() { | |||
| 199 | 197 | } | |
| 200 | 198 | ||
| 201 | 199 | export function testBase64Encode_PNG_WithQuality() { | |
| 202 | - // >> imagesource-to-base-string | ||
| 203 | 200 | const img = imageSource.fromFile(smallImagePath); | |
| 204 | 201 | let base64String = img.toBase64String("png", 80); | |
| 205 | - // << imagesource-to-base-string | ||
| 206 | - | ||
| 207 | 202 | base64String = base64String.substr(0, expectedPngStart.length); | |
| 208 | 203 | TKUnit.assertEqual( | |
| 209 | 204 | base64String, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,14 +98,14 @@ export class ImageSource { | |||
| 98 | 98 | * Saves this instance to the specified file, using the provided image format and quality. | |
| 99 | 99 | * @param path The path of the file on the file system to save to. | |
| 100 | 100 | * @param format The format (encoding) of the image. | |
| 101 | - * @param quality Optional parameter, specifying the quality of the encoding. Defaults to the maximum available quality. | ||
| 101 | + * @param quality Optional parameter, specifying the quality of the encoding. Defaults to the maximum available quality. Quality varies on a scale of 0 to 100. | ||
| 102 | 102 | */ | |
| 103 | 103 | saveToFile(path: string, format: "png" | "jpeg" | "jpg", quality?: number): boolean; | |
| 104 | 104 | ||
| 105 | 105 | /** | |
| 106 | 106 | * Converts the image to base64 encoded string, using the provided image format and quality. | |
| 107 | 107 | * @param format The format (encoding) of the image. | |
| 108 | - * @param quality Optional parameter, specifying the quality of the encoding. Defaults to the maximum available quality. | ||
| 108 | + * @param quality Optional parameter, specifying the quality of the encoding. Defaults to the maximum available quality. Quality varies on a scale of 0 to 100. | ||
| 109 | 109 | */ | |
| 110 | 110 | toBase64String(format: "png" | "jpeg" | "jpg", quality?: number): string; | |
| 111 | 111 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -130,7 +130,7 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 130 | 130 | return false; | |
| 131 | 131 | } | |
| 132 | 132 | ||
| 133 | - if (quality != null && quality > 1) { | ||
| 133 | + if (quality) { | ||
| 134 | 134 | quality = quality - 0 / (100 - 0); // Normalize quality on a scale of 0 to 1 | |
| 135 | 135 | } | |
| 136 | 136 | ||
@@ -148,7 +148,7 @@ export class ImageSource implements ImageSourceDefinition { | |||
| 148 | 148 | return res; | |
| 149 | 149 | } | |
| 150 | 150 | ||
| 151 | - if (quality != null && quality > 1) { | ||
| 151 | + if (quality) { | ||
| 152 | 152 | quality = quality - 0 / (100 - 0); // Normalize quality on a scale of 0 to 1 | |
| 153 | 153 | } | |
| 154 | 154 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments