Ejemplo n.º 1
0
        public void KrakenClient_CustomRequestRemoveGeoData_IsTrue()
        {
            var krakenClient = HelperFunctions.CreateWorkingClient();

            var request = new OptimizeWaitRequest(new Uri(TestData.ImageGeoTag));

            var response = krakenClient.OptimizeWait(request);
            var result   = response.Result;

            Assert.IsTrue(result.Body != null);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl));

            var localFile = HelperFunctions.DownloadImage(result.Body.KrakedUrl);

            try
            {
                using (var reader = new ExifReader(localFile))
                {
                }

                Assert.IsTrue(false, "No Exception");
            }
            catch (Exception)
            {
                Assert.IsTrue(true, "No Exif data");
            }
        }
Ejemplo n.º 2
0
        public void KrakenClient_CustomRequestChangeSize_IsTrue()
        {
            var krakenClient = HelperFunctions.CreateWorkingClient();

            var request = new OptimizeWaitRequest(new Uri(TestData.ImageOne))
            {
                ResizeImage = new ResizeImage
                {
                    Height          = 100,
                    Width           = 100,
                    BackgroundColor = "#ffffff",
                    Strategy        = Strategy.exact
                }
            };

            var response = krakenClient.OptimizeWait(request);
            var result   = response.Result;

            Assert.IsTrue(result.Body != null);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl));

            var localFile = HelperFunctions.DownloadImage(result.Body.KrakedUrl);

            var img = Image.FromFile(localFile);

            Assert.IsTrue(img.Height == 100);
            Assert.IsTrue(img.Width == 100);
        }
Ejemplo n.º 3
0
        public void KrakenClient_CustomRequestConvertImageFormat_IsTrue()
        {
            var krakenClient = HelperFunctions.CreateWorkingClient();

            var request = new OptimizeWaitRequest(new Uri(TestData.ImageOne))
            {
                ConvertImage = new ConvertImage(ImageFormat.gif)
            };

            var response = krakenClient.OptimizeWait(request);
            var result   = response.Result;

            Assert.IsTrue(result.Body != null);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl));
            Assert.IsTrue(result.Body.KrakedUrl.EndsWith(".gif"));
        }
Ejemplo n.º 4
0
        public void KrakenClient_CustomRequestKeepGeoData_IsTrue()
        {
            var krakenClient = HelperFunctions.CreateWorkingClient();

            var request = new OptimizeWaitRequest(new Uri(TestData.ImageGeoTag))
            {
                PreserveMeta = new[] { PreserveMeta.Geotag }
            };

            var response = krakenClient.OptimizeWait(request);
            var result   = response.Result;

            Assert.IsTrue(result.StatusCode == HttpStatusCode.OK);
            Assert.IsTrue(result.Body != null);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl));

            var localFile = HelperFunctions.DownloadImage(result.Body.KrakedUrl);

            try
            {
                using (var reader = new ExifReader(localFile))
                {
                    double[] GpsLongArray;
                    double[] GpsLatArray;
                    double   GpsLongDouble = 0;
                    double   GpsLatDouble  = 0;

                    if (reader.GetTagValue(ExifTags.GPSLongitude, out GpsLongArray) &&
                        reader.GetTagValue(ExifTags.GPSLatitude, out GpsLatArray))
                    {
                        GpsLongDouble = GpsLongArray[0] + GpsLongArray[1] / 60 + GpsLongArray[2] / 3600;
                        GpsLatDouble  = GpsLatArray[0] + GpsLatArray[1] / 60 + GpsLatArray[2] / 3600;
                    }

                    Assert.IsTrue(GpsLongDouble == 120.7602005);
                    Assert.IsTrue(GpsLatDouble == 21.958606694444445);
                }
            }
            catch (Exception)
            {
                Assert.IsTrue(false, "No Exif data");
            }
        }
Ejemplo n.º 5
0
        public void KrakenClient_CustomRequestOptimizeCheckResultBody_IsTrue()
        {
            var krakenClient = HelperFunctions.CreateWorkingClient();

            var request = new OptimizeWaitRequest(new Uri(TestData.ImageOne))
            {
                Lossy = true
            };

            var response = krakenClient.OptimizeWait(request);
            var result   = response.Result;

            Assert.IsTrue(result.Success);
            Assert.IsTrue(result.Body != null);

            // Can only check if we have data, cant check if lossy has been applied
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.FileName));
            Assert.IsTrue(result.Body.KrakedSize > 0);
            Assert.IsTrue(!string.IsNullOrEmpty(result.Body.KrakedUrl));
            Assert.IsTrue(result.Body.OriginalSize > 0);
            Assert.IsTrue(result.Body.SavedBytes > 0);
        }