working on it ...

Filters

Explore Public Snippets

Sort by

Found 820 snippets matching: jpg

    public by antlong  489216  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 Geometry  125442  0  5  0

    FromFile: Load bitmap from file.

    Load bitmap from file. File name to load bitmap from. Returns loaded bitmap. The method is provided as an alternative of method to solve the issues of locked file. The standard .NET's method locks the source file until image's object is disposed, so the file can not be deleted or overwritten. This method workarounds the issue and
    /// <summary>
    /// Load bitmap from file.
    /// </summary>
    /// 
    /// <param name="fileName">File name to load bitmap from.</param>
    /// 
    /// <returns>Returns loaded bitmap.</returns>
    /// 
    /// <remarks><para>The method is provided as an alternative of <see cref="System.Drawing.Image.FromFile(string)"/>
    /// method to solve the issues of locked file. The standard .NET's method locks the source file until
    /// image's object is disposed, so the file can not be deleted or overwritten. This method workarounds the issue and
    /// does not lock the source file.</para>
    /// 
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = Accord.Imaging.Image.FromFile( "test.jpg" );
    /// </code>
    /// </remarks>
    /// 
    public static System.Drawing.Bitmap FromFile(string fileName)
    {
        Bitmap loadedImage = null;
        FileStream stream = null;
    
        try
        {
            // read image to temporary memory stream
            stream = File.OpenRead(fileName);
            MemoryStream memoryStream = new MemoryStream();
    
            byte[] buffer = new byte[10000];
            while (true)
            {
                int read = stream.Read(buffer, 0, 10000);
    
                if (read == 0)
                    break;
    
                memoryStream.Write(buffer, 0, read);
            }
    
            loadedImage = (Bitmap)Bitmap.FromStream(memoryStream);
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
                stream.Dispose();
            }
        }
    
        return loadedImage;
    }

    public by Geometry  81830  0  5  0

    GetFormat: Gets the image format most likely associated with a given file name.

    Gets the image format most likely associated with a given file name. The filename in the form "image.jpg". The most likely associated with the given .
    /// <summary>
    ///   Gets the image format most likely associated with a given file name.
    /// </summary>
    /// 
    /// <param name="fileName">The filename in the form "image.jpg".</param>
    /// 
    /// <returns>The <see cref="ImageFormat"/> most likely associated with
    ///   the given <paramref name="fileName"/>.</returns>
    /// 
    public static ImageFormat GetFormat(string fileName)
    {
        string extension = Path.GetExtension(fileName);
    
        if (string.IsNullOrEmpty(extension))
            throw new ArgumentException("Unable to determine file extension for fileName: " + fileName);
    
        switch (extension.ToUpperInvariant())
        {
            case @".BMP":
                return ImageFormat.Bmp;
    
            case @".GIF":
                return ImageFormat.Gif;
    
            case @".ICO":
                return ImageFormat.Icon;
    
            case @".JPG":
            case @".JPEG":
                return ImageFormat.Jpeg;
    
            case @".PNG":
                return ImageFormat.Png;
    
            case @".TIF":
            case @".TIFF":
                return ImageFormat.Tiff;
    
            case @".WMF":
                return ImageFormat.Wmf;
    
            case @".EMF":
                return ImageFormat.Emf;
    
            default:
                throw new NotImplementedException();
        }
    }

    public by Peter Johnson a.k.a. insertcoffee  1443  2  3  0

    convert jpg files to pdf resized for A4

    convert jpg files to pdf resized for A4: convert.sh
    convert -compress jpeg -resize 1240x1753 -units PixelsPerInch -density 150x150 one.jpg two.jpg out.pdf
    
    

    public by Dionnerain  1295  0  4  0

    how to better use JPG to PDF Convert

    There is little doubt that you have to locate an overlooked JPG to PDF Converter is that it provides just enough JPG to PDF. One detail to bear in mind is that JPG to PDF Converter is not always noticeably better. 
    http://sourceforge.net/projects/convertjpgtopdf/

    public by zonaro  9396  291  7  0

    Convert a Image Type HttpPostedFile to Base64 String or DataURL

    Allow you to convert Images (jpg, png or gif images) in HttpPostedFile to a Base64 String or a full DataURL with MIME Type Detection
    public static string ToBase64(this HttpPostedFile PostedFile, bool DataUrl = false)
            {
    
                if (PostedFile.ContentType.ToLower() == "image/jpg" || PostedFile.ContentType.ToLower() == "image/jpeg" || PostedFile.ContentType.ToLower() == "image/pjpeg" || PostedFile.ContentType.ToLower() == "image/gif" || PostedFile.ContentType.ToLower() == "image/x-png" || PostedFile.ContentType.ToLower() == "image/png")
                {
    
                    using (MemoryStream ms = new MemoryStream())
                    {
                        PostedFile.InputStream.CopyTo(ms);
                        byte[] fileBytes = ms.ToArray();
                        return (DataUrl ? "data:" + PostedFile.ContentType + ";base64," + Convert.ToBase64String(fileBytes, 0, (int)ms.Length) : Convert.ToBase64String(fileBytes, 0, (int)ms.Length));
                    }
                }
    
                else
                {
                    return "";
                }
            }

    external by YUTANI MIki  137  0  2  0

    change-jpg-file-names.sh - Change jpg filenames using exif:DateTime

    change-jpg-file-names.sh - Change jpg filenames using exif:DateTime: change-jpg-file-names.sh
    #!/bin/sh
    
    PROGNAME=$(basename $0)
    VERSION="0.3"
    
    usage() {
        echo "Usage: $PROGNAME [OPTIONS]"
        echo
        echo "Options:"
        echo "  -h, --help    help"
        echo "  -V, --version version"
        echo "  -x, --exec    execute"
        echo
        exit 1
    }
    
    execmode=0
    
    for OPT in "$@"
    do
        case "$OPT" in
            '-h'|'--help' )
                usage
                exit 1
                ;;
            '-V'|'--version' )
                echo "$PROGNAME Version $VERSION"
                exit 1
                ;;
            '-x'|'--exec' )
                execmode=1
                shift 1
                ;;
            -*)
                echo "$PROGNAME: illegal option -- '$(echo $1 | sed 's/^-*//')'" 1>&2
                exit 1
                ;;
            *)
                echo "$PROGNAME: illegal parameter -- '$(echo $1 | sed 's/^-*//')'" 1>&2
                exit 1
                ;;
        esac
    done
    
    if [ $execmode = 0 ]
    then echo '#### Not execution, just only print commands ####'
    fi
    
    n='(initial)'
    c=0
    for f in `ls -1 IMG_*.JPG`
    do
      p=$n
      n=`identify -verbose $f | grep exif:DateTime: | sed 's/ *exif:DateTime: *[0-9]\{2\}\([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\).*$/\1\2\3/'`
      if [ $n = $p ]
      then c=`expr $c + 1`
      else c=1
      fi
      if [ $execmode = 1 ]
      then mv -v -i -b $f ${n}_`printf "%02d" ${c}`.JPG
      else echo mv -v -i -b $f ${n}_`printf "%02d" ${c}`.JPG
      fi
    done
    
    
    

    external by hagope  466  0  3  0

    renames jpg files using exif creation date as filename in the same format as Dropbox Camera Uploads folder YYYY-MM-DD HH.MM.SS.jpg

    renames jpg files using exif creation date as filename in the same format as Dropbox Camera Uploads folder YYYY-MM-DD HH.MM.SS.jpg: rename-pictures-for-dropbox.sh
    #!/bin/bash
    
    # requires exif command line utility
    
    shopt -s nocaseglob #find both *.jpg and *.JPG 
    
    for i in *.JPG; do
      j=`exif -t 0x9003 "$i" | grep Value: | sed 's/Value://' | sed s/:/-/g | sed s/-/./3 | sed s/-/./3`.jpg
      mv -i "$i" "$j"
    done
    
    

    external by ChrisCummins  162  0  2  0

    The JPG+RAW cure: Remove those pesky jpg sidecar files

    The JPG+RAW cure: Remove those pesky jpg sidecar files: remove-jpg-sidecars.sh
    #!/usr/bin/env bash
    #
    # remove-jpg-sidecars.sh
    #
    # A script to remove the .jpg sidecar files which are generated by
    # cameras capturing in JPG+RAW mode.
    #
    # How it works:
    #
    #   1) It generates a list of all dng files in the current directory.
    #   2) It generates a list of all jpg files in the current directory.
    #   3) It checks for common file names in the two lists.
    #   4) It removes the 'jpg' version of common files.
    #
    set -eu
    
    # Tidy up after ourselves.
    function finish {
        rm -f .jpgs .dngs .common
    }
    trap finish EXIT
    
    # Detect files.
    echo -n "Detecting dng files ... "
    find . -iname '*.dng' | sed -r 's/\.dng$//I' > .dngs
    echo "done"
    
    echo -n "Detecting jpg files ... "
    find . -iname '*.jpg' | sed -r 's/\.jpg$//I' > .jpgs
    echo "done"
    
    echo -n "Matching common file names ... "
    comm -1 -2 .jpgs .dngs > .common
    echo "done"
    
    # Store line counts.
    num_jpgs=$(wc -l .jpgs | awk '{print $1;}')
    num_dngs=$(wc -l .dngs | awk '{print $1;}')
    num_common=$(wc -l .common | awk '{print $1;}')
    total=$((num_jpgs+num_dngs))
    
    echo
    echo "  # of DNGs in library: $num_dngs"
    echo "  # of JPGs in library: $num_jpgs"
    echo "    Total library size: $total"
    echo
    echo "     # of JPG sidecars: $num_common"
    echo
    
    while true; do
        read -p "Do you wish to remove $num_common sidecar jpgs? (yes/no) " yn
        case $yn in
            [Yy]* )
                echo
                i=1
                while read line; do
                    if [[ -f "$line.jpg" ]] && [[ -f "$line.dng" ]]; then
                        jpg=$(find . -ipath "$line.jpg")
                        echo "($i / $num_common) $jpg"
                        i=$((i+1))
                        # Remove the file!
                        rm "$jpg"
                    fi
                done < .common
                break;;
            [Nn]* )
                exit;;
            * )
                echo "Please answer yes or no.";;
        esac
    done
    
    

    external by Wilco Verhoeven  139  0  2  0

    OSX bash script to reduce image (jpg) size, by resizing, removing color profiles and saving with a jpg quality of 70%.

    OSX bash script to reduce image (jpg) size, by resizing, removing color profiles and saving with a jpg quality of 70%.: resize.sh
    #!/bin/bash
    
    find . -type f \( -name '*.jpg' -o -name '*.JPG' -o -name '*.jpeg' -o -name '*.JPEG' \) -print0 | xargs -0 sips $(file) --resampleHeightWidthMax 2000 --deleteProperty profile --setProperty formatOptions 70
    
    
    • Public Snippets
    • Channels Snippets