Ejemplo n.º 1
0
        private void AnalyzeProfileOriginal(string key)
        {
            var profileOriginalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key);

            if (profileOriginalBlob != null)
            {
                var  dataTable = PoliticiansImagesData.GetData(key);
                bool nullIt    = dataTable.Count == 1 &&
                                 dataTable[0].ProfileOriginalDate <= dataTable[0].HeadshotDate;
                byte[]       newBlob      = null;
                MemoryStream memoryStream = new MemoryStream(profileOriginalBlob);
                Image        image        = Image.FromStream(memoryStream);
                if (nullIt)
                {
                    AppendStatusText("{0}: {1}x{2} {3}->{4} [{5}:{6}]",
                                     key, image.Width, image.Height, profileOriginalBlob.Length,
                                     0, profileOriginalBlob.Length,
                                     ImageManager.GetContentType(image).Replace("image/", ""));
                }
                else
                {
                    newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 0, 0);
                    AppendStatusText("{0}: {1}x{2} {3}->{4} [{5}:{6}]",
                                     key, image.Width, image.Height, profileOriginalBlob.Length,
                                     newBlob.Length, profileOriginalBlob.Length - newBlob.Length,
                                     ImageManager.GetContentType(image).Replace("image/", ""));
                    File.WriteAllBytes(@"c:\ProfileOriginals\" + key + ".jpg", newBlob);
                }
            }
        }
Ejemplo n.º 2
0
        protected void ButtonNoCrop_Click(object sender, EventArgs e)
        {
            try
            {
                var politicianKey = LabelPoliticianKey.Text;

                // We get the current profile original, convert it to a stream, then
                // use it as the HeadshotOriginal image
                var blob = PoliticiansImagesBlobs.GetProfileOriginal(politicianKey);
                if (blob == null)
                {
                    return;
                }
                var uploadTime = DateTime.UtcNow;
                var stream     = new MemoryStream(blob);

                Size originalSize;
                ImageManager.UpdateAllPoliticianHeadshotImages(politicianKey, stream,
                                                               uploadTime, out originalSize);
                CommonCacheInvalidation.ScheduleInvalidation("politicianimage",
                                                             politicianKey);

                MarkProcessed();
                UpdateRowCountAfterChange();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Ejemplo n.º 3
0
        private void FixHeadshots(string key)
        {
            byte[] originalBlob = null;
            var    logTable     = LogPoliticiansImagesHeadshot.GetLatestData(key);

            if (logTable.Count > 0)
            {
                originalBlob = logTable[0].HeadshotOriginal;
            }
            else
            {
                originalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key);
            }
            if (originalBlob != null)
            {
                MemoryStream memoryStream = new MemoryStream(originalBlob);
                Image        image        = Image.FromStream(memoryStream);

                var newBlob100 = ImageManager.GetResizedImageBlobAsJpg(image, 100, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot100\" + key + ".jpg", newBlob100);
                PoliticiansImagesBlobs.UpdateHeadshot100(newBlob100, key);

                var newBlob75 = ImageManager.GetResizedImageBlobAsJpg(image, 75, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot75\" + key + ".jpg", newBlob75);
                PoliticiansImagesBlobs.UpdateHeadshot75(newBlob75, key);

                var newBlob50 = ImageManager.GetResizedImageBlobAsJpg(image, 50, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot50\" + key + ".jpg", newBlob50);
                PoliticiansImagesBlobs.UpdateHeadshot50(newBlob50, key);

                var newBlob35 = ImageManager.GetResizedImageBlobAsJpg(image, 35, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot35\" + key + ".jpg", newBlob35);
                PoliticiansImagesBlobs.UpdateHeadshot35(newBlob35, key);

                var newBlob25 = ImageManager.GetResizedImageBlobAsJpg(image, 25, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot25\" + key + ".jpg", newBlob25);
                PoliticiansImagesBlobs.UpdateHeadshot25(newBlob25, key);

                var newBlob20 = ImageManager.GetResizedImageBlobAsJpg(image, 20, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot20\" + key + ".jpg", newBlob20);
                PoliticiansImagesBlobs.UpdateHeadshot20(newBlob20, key);

                var newBlob15 = ImageManager.GetResizedImageBlobAsJpg(image, 15, 0);
                File.WriteAllBytes(@"c:\VoteImages\Headshot15\" + key + ".jpg", newBlob15);
                PoliticiansImagesBlobs.UpdateHeadshot15(newBlob15, key);

                AppendStatusText("processed: {0}", key);
            }
            else
            {
                AppendStatusText("no original: {0}", key);
            }
        }
Ejemplo n.º 4
0
        private void ConvertProfileOriginal(string key)
        {
            var profileOriginalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key);

            if (profileOriginalBlob != null)
            {
                MemoryStream memoryStream = new MemoryStream(profileOriginalBlob);
                Image        image        = Image.FromStream(memoryStream);
                var          newBlob      = ImageManager.GetResizedImageBlobAsJpg(image, 1600, 1600);
                File.WriteAllBytes(@"c:\VoteImages\ProfileOriginal\" + key + ".jpg", newBlob);
                PoliticiansImagesBlobs.UpdateProfileOriginal(newBlob, key);
                AppendStatusText("{0}: {1} -> {2}", key, profileOriginalBlob.Length, newBlob.Length);
            }
        }
Ejemplo n.º 5
0
        //private void ConvertHeadshotImages(string key)
        //{
        //  var headshotOriginalBlob = PoliticiansImagesBlobs.GetHeadshotOriginal(key);
        //  if (headshotOriginalBlob != null)
        //  {
        //    MemoryStream memoryStream = new MemoryStream(headshotOriginalBlob);
        //    Image image = Image.FromStream(memoryStream);
        //    var newBlob100 = ImageManager.GetResizedImageBlobAsJpg(image, 100, 100);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot100\" + key + ".jpg", newBlob100);
        //    PoliticiansImagesBlobs.UpdateHeadshot100(newBlob100, key);
        //    var newBlob75 = ImageManager.GetResizedImageBlobAsJpg(image, 75, 75);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot75\" + key + ".jpg", newBlob75);
        //    PoliticiansImagesBlobs.UpdateHeadshot75(newBlob75, key);
        //    var newBlob50 = ImageManager.GetResizedImageBlobAsJpg(image, 50, 50);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot50\" + key + ".jpg", newBlob50);
        //    PoliticiansImagesBlobs.UpdateHeadshot50(newBlob50, key);
        //    var newBlob35 = ImageManager.GetResizedImageBlobAsJpg(image, 35, 35);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot35\" + key + ".jpg", newBlob35);
        //    PoliticiansImagesBlobs.UpdateHeadshot35(newBlob35, key);
        //    var newBlob25 = ImageManager.GetResizedImageBlobAsJpg(image, 25, 25);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot25\" + key + ".jpg", newBlob25);
        //    PoliticiansImagesBlobs.UpdateHeadshot25(newBlob25, key);
        //    var newBlob20 = ImageManager.GetResizedImageBlobAsJpg(image, 20, 20);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot20\" + key + ".jpg", newBlob20);
        //    PoliticiansImagesBlobs.UpdateHeadshot20(newBlob20, key);
        //    var newBlob15 = ImageManager.GetResizedImageBlobAsJpg(image, 15, 15);
        //    File.WriteAllBytes(@"c:\VoteImages\Headshot15\" + key + ".jpg", newBlob15);
        //    PoliticiansImagesBlobs.UpdateHeadshot15(newBlob15, key);
        //    AppendStatusText(key);
        //  }
        //  else
        //  {
        //    Byte[] headshotBlob;
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot100(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 100, 100);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot100\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot100(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot75(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 75, 75);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot75\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot75(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot50(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 50, 50);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot50\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot50(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot35(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 35, 35);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot35\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot35(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot25(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 25, 25);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot25\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot25(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot20(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 20, 20);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot20\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot20(newBlob, key);
        //    }
        //    headshotBlob = PoliticiansImagesBlobs.GetHeadshot15(key);
        //    if (headshotBlob != null)
        //    {
        //      MemoryStream memoryStream = new MemoryStream(headshotBlob);
        //      Image image = Image.FromStream(memoryStream);
        //      var newBlob = ImageManager.GetResizedImageBlobAsJpg(image, 15, 15);
        //      File.WriteAllBytes(@"c:\VoteImages\Headshot15\" + key + ".jpg", newBlob);
        //      PoliticiansImagesBlobs.UpdateHeadshot15(newBlob, key);
        //    }
        //  }
        //}

        private void ConvertProfileImages(string key)
        {
            var profileOriginalBlob = PoliticiansImagesBlobs.GetProfileOriginal(key);

            if (profileOriginalBlob != null)
            {
                MemoryStream memoryStream = new MemoryStream(profileOriginalBlob);
                Image        image        = Image.FromStream(memoryStream);
                var          newBlob300   = ImageManager.GetResizedImageBlobAsJpg(image, 300, 400);
                File.WriteAllBytes(@"c:\VoteImages\Profile300\" + key + ".jpg", newBlob300);
                PoliticiansImagesBlobs.UpdateProfile300(newBlob300, key);
                var newBlob200 = ImageManager.GetResizedImageBlobAsJpg(image, 200, 275);
                File.WriteAllBytes(@"c:\VoteImages\Profile200\" + key + ".jpg", newBlob200);
                PoliticiansImagesBlobs.UpdateProfile200(newBlob200, key);
                AppendStatusText(key);
            }
            else
            {
                var profile300Blob = PoliticiansImagesBlobs.GetProfile300(key);
                if (profile300Blob != null)
                {
                    MemoryStream memoryStream = new MemoryStream(profile300Blob);
                    Image        image        = Image.FromStream(memoryStream);
                    var          newBlob300   = ImageManager.GetResizedImageBlobAsJpg(image, 300, 400);
                    File.WriteAllBytes(@"c:\VoteImages\Profile300\" + key + ".jpg", newBlob300);
                    PoliticiansImagesBlobs.UpdateProfile300(newBlob300, key);
                }
                var profile200Blob = PoliticiansImagesBlobs.GetProfile200(key);
                if (profile200Blob != null)
                {
                    MemoryStream memoryStream = new MemoryStream(profile200Blob);
                    Image        image        = Image.FromStream(memoryStream);
                    var          newBlob200   = ImageManager.GetResizedImageBlobAsJpg(image, 200, 275);
                    File.WriteAllBytes(@"c:\VoteImages\Profile200\" + key + ".jpg", newBlob200);
                    PoliticiansImagesBlobs.UpdateProfile200(newBlob200, key);
                }
            }
        }