working on it ...

Filters

Explore Public Snippets

Sort by

Found 7,650 snippets matching: images

    public by antlong  489193  15  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by clsw  350038  0  6  1

    Image upload to API, return direct link. (IMGUR)

    Imgur, one of the best image hosts in the world, has a fantastic API, this is a VERY simple and usable implementation of it, just pass an image to the function and it will return the direct link to yout image, heavily commented and easy to use.
    public string UploadImage(Image img)
            {
                //get a dev key from api.imgur.com, anonymous usage (no user auth) only.
                string devkey = "YOUR_CLIENT_ID (e.g. abcde1f234567g8)";
    
                //define the WebClient we'll use to communicate with Imgur.
                WebClient w = new WebClient();
                
                //adds the Header to authorize this application with Imgur, must include a valid CLIENT_ID from 'devkey' above.
                w.Headers.Add("Authorization", "Client-ID " + devkey);
    
                System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
                try
                {
                    //Converts the image to a byte array so it can be turned into a string for upload.
                    using (MemoryStream stream = new MemoryStream())
                    {
                        img.Save(stream, ImageFormat.Png);
                        Keys.Add("image", Convert.ToBase64String(stream.ToArray()));
                    }
                    
                    //uploads the string-formatted-image and waits for the response.
                    byte[] responseArray = w.UploadValues("https://api.imgur.com/3/image", Keys);
                    dynamic result = Encoding.ASCII.GetString(responseArray);
    
                    //formats the (long and technical) result into just the direct image link.
                    Regex reg = new Regex("link\":\"(.*?)\""); Match match = reg.Match(result);
                    string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
    
                    //returns the online address of the image.
                    return url;
                }
                catch (Exception s) { MessageBox.Show(s.Message); return "err"; }
            }

    public by talaverars  168552  0  4  0

    the imagestock the best way to design

    the imagestock the best way to design : gistfile1.txt
    enter www.imagestock.com.mx
    
    

    public by sherazam  4287  5  6  0

    How to Convert JPEG, PNG, BMP, EMF, WMF & GIF Images to PDF in .NET Apps

    // Enter here the actual content of the snippet.            
    // Convert single frame JPEG, PNG, BMP & Multi-frame TIF or GIF images to PDF
    
    //[C# Code Sample]
    
    // // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    // The path to the documents directory.
    string dataDir = RunExamples.GetDataDir_LoadingAndSaving();
    
    ConvertImageToPdf(dataDir + "Test.jpg", dataDir + "TestJpg_out_.pdf");
    ConvertImageToPdf(dataDir + "Test.png", dataDir + "TestPng_out_.pdf");
    ConvertImageToPdf(dataDir + "Test.wmf", dataDir + "TestWmf_out_.pdf");
    ConvertImageToPdf(dataDir + "Test.tiff", dataDir + "TestTif_out_.pdf");
    ConvertImageToPdf(dataDir + "Test.gif", dataDir + "TestGif_out_.pdf");
    
    //[VB Code Sample]
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    ' The path to the documents directory.
    Dim dataDir As String = RunExamples.GetDataDir_LoadingAndSaving()
    
    ConvertImageToPdf(dataDir & Convert.ToString("Test.jpg"), dataDir & Convert.ToString("TestJpg_out_.pdf"))
    ConvertImageToPdf(dataDir & Convert.ToString("Test.png"), dataDir & Convert.ToString("TestPng_out_.pdf"))
    ConvertImageToPdf(dataDir & Convert.ToString("Test.wmf"), dataDir & Convert.ToString("TestWmf_out_.pdf"))
    ConvertImageToPdf(dataDir & Convert.ToString("Test.tiff"), dataDir & Convert.ToString("TestTiff_out_.pdf"))
    ConvertImageToPdf(dataDir & Convert.ToString("Test.gif"), dataDir & Convert.ToString("TestGif_out_.pdf"))
    
    
    //Using ConvertImageToPdf method
    
    //[C# Code Sample]
     
    
    // For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    // Create Aspose.Words.Document and DocumentBuilder. 
    // The builder makes it simple to add content to the document.
    Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    
    // Read the image from file, ensure it is disposed.
    using (Image image = Image.FromFile(inputFileName))
    {
        // Find which dimension the frames in this image represent. For example 
        // the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension". 
        FrameDimension dimension = new FrameDimension(image.FrameDimensionsList[0]);
    
        // Get the number of frames in the image.
        int framesCount = image.GetFrameCount(dimension);
    
        // Loop through all frames.
        for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
        {
            // Insert a section break before each new page, in case of a multi-frame TIFF.
            if (frameIdx != 0)
                builder.InsertBreak(BreakType.SectionBreakNewPage);
    
            // Select active frame.
            image.SelectActiveFrame(dimension, frameIdx);
    
            // We want the size of the page to be the same as the size of the image.
            // Convert pixels to points to size the page to the actual image size.
            PageSetup ps = builder.PageSetup;
            ps.PageWidth = ConvertUtil.PixelToPoint(image.Width, image.HorizontalResolution);
            ps.PageHeight = ConvertUtil.PixelToPoint(image.Height, image.VerticalResolution);
    
            // Insert the image into the document and position it at the top left corner of the page.
            builder.InsertImage(
                image,
                RelativeHorizontalPosition.Page,
                0,
                RelativeVerticalPosition.Page,
                0,
                ps.PageWidth,
                ps.PageHeight,
                WrapType.None);
        }
    }
    
    // Save the document to PDF.
    doc.Save(outputFileName);
     
    //[VB.NET Code Sample]
     
    
    ' For complete examples and data files, please go to https://github.com/asposewords/Aspose_Words_NET
    ' Create Aspose.Words.Document and DocumentBuilder. 
    ' The builder makes it simple to add content to the document.
    Dim doc As New Document()
    Dim builder As New DocumentBuilder(doc)
    
    ' Read the image from file, ensure it is disposed.
    Using image__1 As Image = Image.FromFile(inputFileName)
        ' Find which dimension the frames in this image represent. For example 
        ' the frames of a BMP or TIFF are "page dimension" whereas frames of a GIF image are "time dimension". 
        Dim dimension As New FrameDimension(image__1.FrameDimensionsList(0))
    
        ' Get the number of frames in the image.
        Dim framesCount As Integer = image__1.GetFrameCount(dimension)
    
        ' Loop through all frames.
        For frameIdx As Integer = 0 To framesCount - 1
            ' Insert a section break before each new page, in case of a multi-frame TIFF.
            If frameIdx <> 0 Then
                builder.InsertBreak(BreakType.SectionBreakNewPage)
            End If
    
            ' Select active frame.
            image__1.SelectActiveFrame(dimension, frameIdx)
    
            ' We want the size of the page to be the same as the size of the image.
            ' Convert pixels to points to size the page to the actual image size.
            Dim ps As PageSetup = builder.PageSetup
            ps.PageWidth = ConvertUtil.PixelToPoint(image__1.Width, image__1.HorizontalResolution)
            ps.PageHeight = ConvertUtil.PixelToPoint(image__1.Height, image__1.VerticalResolution)
    
            ' Insert the image into the document and position it at the top left corner of the page.
            builder.InsertImage(image__1, RelativeHorizontalPosition.Page, 0, RelativeVerticalPosition.Page, 0, ps.PageWidth, _
                ps.PageHeight, WrapType.None)
        Next
    End Using
    
    ' Save the document to PDF.
    doc.Save(outputFileName)
    
    

    public by sherazam  4172  1  6  0

    How to Combine Two or Multiple Images into a Single Image inside .NET Apps

    This technical tip explains how .NET developers can combine single or multiple images inside their .NET applications. This example uses Graphics class and shows how to combine two or more images into a single complete image. To demonstrate the operation, the example creates a new Image canvas in JPEG format and draw images on the canvas surface us
    // Enter here the actual content of the snippet.            
    // Combining Images using Graphics Class
    
    //[C# Code Sample]
    
    //Create an instance of JpegOptions and set its various properties
    Aspose.Imaging.ImageOptions.JpegOptions ImageOptions = new Aspose.Imaging.ImageOptions.JpegOptions();
    
    //Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = new Aspose.Imaging.Sources.FileCreateSource(@"two_images_result.jpeg", false);
    
    //Create an instance of Image and define canvas size
    using (var image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600))
    {
          //Create and initialize an instance of Graphics
          var graphics = new Aspose.Imaging.Graphics(image);
    
          //Clear the image surface with white color
          graphics.Clear(Aspose.Imaging.Color.White);
    
          // Draw Image
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input1.jpg"), 0, 0, 600, 300);
          graphics.DrawImage(Aspose.Imaging.Image.Load(@"input2.jpg"), 0, 300, 600, 300);
                    
          // Call save method to save the resultant image.
          image.Save();
    }
     
    //[VB.NET Code Sample]
    
    'Create an instance of JpegOptions and set its various properties
    Dim ImageOptions As New Aspose.Imaging.ImageOptions.JpegOptions()
    
    'Create an instance of FileCreateSource and assign it to Source property
    ImageOptions.Source = New Aspose.Imaging.Sources.FileCreateSource("two_images_result.jpeg", False)
    
    'Create an instance of Image and define canvas size
    Using image = Aspose.Imaging.Image.Create(ImageOptions, 600, 600)
    	'Create and initialize an instance of Graphics
    	Dim graphics = New Aspose.Imaging.Graphics(image)
    
    	'Clear the image surface with white color
    	graphics.Clear(Aspose.Imaging.Color.White)
    
    	' Draw Image
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input1.jpg"), 0, 0, 600, 300)
    	graphics.DrawImage(Aspose.Imaging.Image.Load("input2.jpg"), 0, 300, 600, 300)
    
    	' Call save method to save the resultant image.
    	image.Save()
    End Using
    
    

    public by sherazam  2701  0  6  1

    How to Read and Write XMP Data to Images inside .NET Apps

    // Enter here the actual content of the snippet.//Create XMP Metadata, Write It And Read From File
    
    //[C# Code Sample]
    
    // Specify the size of image by defining a Rectangle 
    Aspose.Imaging.Rectangle rect = new Aspose.Imaging.Rectangle(0, 0, 100, 200);
    
    TiffOptions tiffOptions = new TiffOptions(TiffExpectedFormat.TiffJpegRGB);
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack;
    tiffOptions.BitsPerSample = new ushort[] { 8 };
    
    // create the brand new image just for sample purposes
    using (var image = new TiffImage(new TiffFrame(tiffOptions, rect.Width, rect.Height)))
    {
          // create an instance of XMP-Header
          Aspose.Imaging.Xmp.XmpHeaderPi xmpHeader = new Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString());
    
          // create an instance of Xmp-TrailerPi 
          Aspose.Imaging.Xmp.XmpTrailerPi xmpTrailer = new Aspose.Imaging.Xmp.XmpTrailerPi(true);
    
          // create an instance of XMPmeta class to set different attributes
          Aspose.Imaging.Xmp.XmpMeta xmpMeta = new Aspose.Imaging.Xmp.XmpMeta();
          xmpMeta.AddAttribute("Author", "Mr Smith");
          xmpMeta.AddAttribute("Description", "The fake metadata value");
    
          // create an instance of XmpPacketWrapper that contains all metadata
          Aspose.Imaging.Xmp.XmpPacketWrapper xmpData = new Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta);
    
          // create an instacne of Photoshop package and set photoshop attributes
          Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage photoshopPackage = new Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage();
          photoshopPackage.SetCity("London");
          photoshopPackage.SetCountry("England");
          photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb);
          photoshopPackage.SetCreatedDate(DateTime.UtcNow);
    
          // add photoshop package into XMP metadata
          xmpData.AddPackage(photoshopPackage);
    
          // create an instacne of DublinCore package and set dublinCore attributes
          Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage dublinCorePackage = new Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage();
          dublinCorePackage.SetAuthor("Charles Bukowski");
          dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts");
          dublinCorePackage.AddValue("dc:movie", "Barfly");
    
          // add dublinCore Package into XMP metadata
          xmpData.AddPackage(dublinCorePackage);
    
          using (var ms = new MemoryStream())
          {
                        // update XMP metadata into image
                        image.XmpData = xmpData;
    
                        // Save image on the disk or in memory stream
                        image.Save(ms);
    
                        ms.Seek(0, System.IO.SeekOrigin.Begin);
    
                        // Load the image from moemory stream or from disk to read/get the metadata
                        using (var img = (TiffImage)Aspose.Imaging.Image.Load(ms))
                        {
                            // getting the XMP metadata
                            Aspose.Imaging.Xmp.XmpPacketWrapper imgXmpData = img.XmpData;
                            foreach (Aspose.Imaging.Xmp.XmpPackage package in imgXmpData.Packages)
                            {
                                // use package data ...
                            }
                        }
         }
    }
     
    //[VB.NET Code Sample]
    
    ' Specify the size of image by defining a Rectangle 
    Dim rect As New Aspose.Imaging.Rectangle(0, 0, 100, 200)
    
    Dim tiffOptions As New TiffOptions(TiffExpectedFormat.TiffJpegRGB)
    tiffOptions.Photometric = TiffPhotometrics.MinIsBlack
    tiffOptions.BitsPerSample = New UShort() {8}
    
    ' create the brand new image just for sample purposes
    Using image = New TiffImage(New TiffFrame(tiffOptions, rect.Width, rect.Height))
    	' create an instance of XMP-Header
    	Dim xmpHeader As New Aspose.Imaging.Xmp.XmpHeaderPi(System.Guid.NewGuid().ToString())
    
    	' create an instance of Xmp-TrailerPi 
    	Dim xmpTrailer As New Aspose.Imaging.Xmp.XmpTrailerPi(True)
    
    	' create an instance of XMPmeta class to set different attributes
    	Dim xmpMeta As New Aspose.Imaging.Xmp.XmpMeta()
    	xmpMeta.AddAttribute("Author", "Mr Smith")
    	xmpMeta.AddAttribute("Description", "The fake metadata value")
    
    	' create an instance of XmpPacketWrapper that contains all metadata
    	Dim xmpData As New Aspose.Imaging.Xmp.XmpPacketWrapper(xmpHeader, xmpTrailer, xmpMeta)
    
    	' create an instacne of Photoshop package and set photoshop attributes
    	Dim photoshopPackage As New Aspose.Imaging.Xmp.Schemas.Photoshop.PhotoshopPackage()
    	photoshopPackage.SetCity("London")
    	photoshopPackage.SetCountry("England")
    	photoshopPackage.SetColorMode(Aspose.Imaging.Xmp.Schemas.Photoshop.ColorMode.Rgb)
    	photoshopPackage.SetCreatedDate(DateTime.UtcNow)
    
    	' add photoshop package into XMP metadata
    	xmpData.AddPackage(photoshopPackage)
    
    	' create an instacne of DublinCore package and set dublinCore attributes
    	Dim dublinCorePackage As New Aspose.Imaging.Xmp.Schemas.DublinCore.DublinCorePackage()
    	dublinCorePackage.SetAuthor("Charles Bukowski")
    	dublinCorePackage.SetTitle("Confessions of a Man Insane Enough to Live With the Beasts")
    	dublinCorePackage.AddValue("dc:movie", "Barfly")
    
    	' add dublinCore Package into XMP metadata
    	xmpData.AddPackage(dublinCorePackage)
    
    	Using ms = New MemoryStream()
    		' update XMP metadata into image
    		image.XmpData = xmpData
    
    		' Save image on the disk or in memory stream
    		image.Save(ms)
    
    		ms.Seek(0, System.IO.SeekOrigin.Begin)
    
    		' Load the image from moemory stream or from disk to read/get the metadata
    		Using img = DirectCast(Aspose.Imaging.Image.Load(ms), TiffImage)
    			' getting the XMP metadata
    			Dim imgXmpData As Aspose.Imaging.Xmp.XmpPacketWrapper = img.XmpData
    					' use package data ...
    			For Each package As Aspose.Imaging.Xmp.XmpPackage In imgXmpData.Packages
    			Next
    		End Using
    	End Using
    End Using
    
    

    public by sTiLL-iLL @ SniPitz-KND  3700  0  8  22

    Lazy Loaded...... Lazy.js

    load your images on demand...
    // another lazy  image loader thang.....
    
    var lazy=(function() {
        this.load=function(elem, res) {
          if (document.querySelectorAll) {
              res=document.querySelectorAll(elem);
          } else {
            var dok=document, 
              sheet=dok.styleSheets[0] ||
              dok.createStyleSheet();
              sheet.addRule(elem,'foo:idx');
            for(var ln=dok.all,idx=0,lst=[],f=l.length;idx<foo;idx++) {
              (ln[isx].currentStyle.foo&&lst.push(ln[idx]));
            }
            sheet.removeRule(0);
            res=clst;
          }
          return res;
        }; 
        var receive=function(evt,func) {
          window.addEventListener?this.addEventListener(evt,func,false) :
            (window.attachEvent)?this.attachEvent('on'+evt,func):
            (this['on'+evt]=func);
        };
        var itHaz=function(k,object) {
          return Object.prototype.hasOwnProperty.call(k,object);
        };
        this.getLoaded=function(elem,func) {
          var img=new Image(),
          prnt=elem.parent;
          img.src=elem.getAttribute('data-src');
          img.addEventListener("load",function(evt) {
          if (!elem.parent) {
            prnt.replaceChild(img, elem)
          } else {
            elem.src=src;
          }
          (func)?func(): null;
        });
        img.src=src;
      };
      function inView(elem){
        var r=elem.getBoundingClientRect();
        return(r.top>=0&&r.left>=0&&
          r.top<=(window.innerHeight||
            document.documentElement.clientHeight)
          );
      }
      function cBak(pix, idx){
        return (pix.splice(idx,idx));
      }
      var pix=[],qry=layzee('img.lazy');
      this.doWork=function(){
        for (var idx=0;idx<images.length;idx++) {
          if (inView(pix[idx])){
            return getLoaded(pix[idx],cBak(pix,idx));
          }
        }
      };
      for (var idx=0;idx<qry.length;idx++) {
        pix.push(qry[idx]);
      }
      doWork();
      receive('scroll',dowork);
    }(this));                      

    public by Geometry  1214  0  6  0

    Fundamental: Creates the fundamental matrix between two images from a set of points from each image.

    Creates the fundamental matrix between two images from a set of points from each image.
    #endregion
    
    
    #region Fundamental Matrix
    /// <summary>
    ///   Creates the fundamental matrix between two
    ///   images from a set of points from each image.
    /// </summary>
    /// 
    public static float[,] Fundamental(PointH[] points1, PointH[] points2, out PointH[] epipoles)
    {
        var F = Fundamental(points1, points2);
    
        SingularValueDecompositionF svd = new SingularValueDecompositionF(F,
            computeLeftSingularVectors: true, computeRightSingularVectors: true,
            autoTranspose: true, inPlace: false);
    
        var U = svd.LeftSingularVectors;
        var V = svd.RightSingularVectors;
    
        PointH e1 = new PointH(V[0, 2] / V[2, 2], V[1, 2] / V[2, 2], 1);
        PointH e2 = new PointH(U[0, 2] / U[2, 2], U[1, 2] / U[2, 2], 1);
    
        epipoles = new PointH[] { e1, e2 };
    
        return F;
    }

    public by zonaro  4370  34  7  1

    Console Hacking - Get all Images of webpage using Jquery

    Just paste it on your webbrowser console and every image will be opened in a new tab (turn off your pop up blocker)
    var imgs = $("img").map(function () { return this.src; });
    for (var i = 0; i < imgs.length; i++) { 
       window.open( imgs[i]); 
    }

    public by johansonkatherine  6770  1  10  5

    Save Microsoft OneNote (.one) file as an image (.PNG, .BMP, .JPEG, .GIF) file in C#/.NET

    The Aspose.Note for .NET API allows developers to open files & manipulate elements of OneNote books & export them to PNG, GIF, JPEG, BMP and PDF formats. The following code sample shows developers how to save OneNote File as an image in C#/.NET
    // Load the document into Aspose.Note.
        Document oneFile = new Document(@"FullFileName.one");
        // Save the document as GIF.
        oneFile.Save("FullFileName.gif", SaveFormat.Gif);
    	
        OR
    
        // Load the document into Aspose.Note.
        Document oneFile = new Document(@"FullFileName.one");
        // Initialize ImageSaveOptions object 
        ImageSaveOptions opts = new ImageSaveOptions(SaveFormat.Png);
        // Set page index
        opts.PageIndex = 1;
        // Save the document as PNG.
        oneFile.Save(@"FullFileName.png", opts);
    
    • Public Snippets
    • Channels Snippets