private void ModelItemToJpeg(BookmarkBucketItem item, string sDir)
        {
            // If the webpage cannot be loaded, we want to create a .html and .jpeg anyways.
            // 1) save html
            string sHtml    = sDir + "\\" + item.GetNameWithoutExtension() + ".html";
            bool   bGotHtml = BookmarkBucketImplementation.DownloadFile(item.sUrl, sHtml);

            File.AppendAllText(sHtml, strHtmlStamp + item.sUrl + "-->"); // will create file.

            // 2) save png screenshot
            string sPng       = sDir + "\\" + item.GetNameWithoutExtension() + ".png";
            bool   bSucceeded = BookmarkBucketImplementation.DownloadWebsiteSnapshot(item.sUrl, sPng);

            if (!bSucceeded)
            {
                using (Bitmap b = ImageHelper.GetBlankBitmap(300, 300)) { b.Save(sPng); }
            }

            // 3) resize and convert png to jpeg
            string sJpeg = sDir + "\\" + item.GetNameWithoutExtension() + ".jpeg";

            ImageHelper.ResizeAndTruncateAndSaveImage(sPng, sJpeg, 400, 300, 0.5f, 84, false);
            File.Delete(sPng);
            if (!File.Exists(sJpeg))
            {
                throw new BookmarkBucketException("Jpeg file expected to be created for '" + item.sFile + "', but was not found");
            }

            // 4) write exif info to jpeg
            BookmarkBucketCore.SetExifData(sJpeg, item.sUrl, item.GetNameWithoutExtension());
        }
Esempio n. 2
0
        private void ConvertOldToNewWithoutRedownloading()
        {
            string sDir = InputBoxForm.GetStrInput("All from this directory:", "c:\\example");

            if (sDir == null || !Directory.Exists(sDir))
            {
                MessageBox.Show("Not a valid directory."); return;
            }

            DirectoryInfo di = new DirectoryInfo(sDir);

            FileInfo[] rgFiles = di.GetFiles("*.jpg");
            foreach (FileInfo fi in rgFiles)
            {
                string sNewname = Path.GetFileNameWithoutExtension(fi.Name.Replace("555 ", "")) + ".png";
                if (File.Exists(sDir + "\\" + sNewname))
                {
                    throw new BookmarkBucketException("exists png" + fi.Name);
                }
                File.Move(sDir + "\\" + fi.Name, sDir + "\\" + sNewname);
            }

            // set the exifs...
            FileInfo[] rgFilesPng = di.GetFiles("*.png");
            foreach (FileInfo fi in rgFilesPng)
            {
                string sOldUrl = BookmarkBucketCore.GetExifData(fi.FullName, "Comment");
                if (!BookmarkBucketCore.looksLikeAUrl(sOldUrl))
                {
                    throw new BookmarkBucketException("couldnot read url" + fi.Name);
                }

                // convert it to a jpg.
                string sJpeg = sDir + "\\" + Path.GetFileNameWithoutExtension(fi.Name) + ".jpeg";
                using (Bitmap b = new Bitmap(fi.FullName))
                {
                    ImageHelper.BitmapSaveJpegQuality(b, sJpeg, 85);
                }
                if (!File.Exists(sJpeg))
                {
                    throw new BookmarkBucketException("no jpeg created?");
                }
                File.Delete(fi.FullName);

                BookmarkBucketCore.StripAllExifData(sJpeg);
                BookmarkBucketCore.SetExifData(sJpeg, sOldUrl, Path.GetFileNameWithoutExtension(fi.Name));

                // download the htm!
                string sHtmlName = sDir + "\\" + Path.GetFileNameWithoutExtension(fi.Name) + ".html";
                if (File.Exists(sHtmlName))
                {
                    throw new BookmarkBucketException("exists html" + fi.Name);
                }
                BookmarkBucketImplementation.DownloadFile(sOldUrl, sHtmlName);
                File.AppendAllText(sHtmlName, strHtmlStamp + sOldUrl + "-->"); // will create file.
            }
        }