working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,600 snippets matching: crop

    public by zonaro  323280  2  7  0

    Crop Image on C#

    Simple snippet to Crop Image from up-left point
    public static Bitmap CropImage(this Bitmap source, Rectangle section)
           {
               Bitmap bmp = new Bitmap(section.Width, section.Height);
               Graphics g = Graphics.FromImage(bmp); 
               g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel); 
               return bmp;
           }
    

    public by sherazam  4265  3  5  0

    How to Crop EMF Image using Shifts or Rectangle Approaches in .NET Applications

    This technical tip explains how .NET developers can Crop an EMF Image inside their .NET applications. Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used to cut out some portion of an image to increase the focus on a particular area. Aspose.Imaging for .Net API supports
    // Enter here the actual content of the snippet.            // Cropping by Shifts
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfBezier.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
      using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
      {
        //Based on the shift values, apply the cropping on image
        //Crop method will shift the image bounds toward the center of image
        image.Crop(30, 40, 50, 60);
    
        // Set height and width
        pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
        pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
        //Save the results to disk
        image.Save(outputStream, pdfOptions);
      }
    }
     
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfBezier.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Based on the shift values, apply the cropping on image
    		'Crop method will shift the image bounds toward the center of image
    		image.Crop(30, 40, 50, 60)
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    // Cropping by Rectangle
    
    //[C# Code Sample]
    
    // create an instance of Rasterization options
    EmfRasterizationOptions emfRasterizationOptions = new EmfRasterizationOptions();
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke;
    
    // create an instance of PNG options
    PdfOptions pdfOptions = new PdfOptions();
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions;
    
    //Declare variables to store file paths for input and output images
    string filePath = @"TestEmfExtPen.emf";
    string outPath = filePath + ".pdf";
    
    //Load an existing image into an instance of EMF class
    using (Aspose.Imaging.FileFormats.Emf.EmfImage image = (Aspose.Imaging.FileFormats.Emf.EmfImage)Aspose.Imaging.Image.Load(filePath))
    {
        using (FileStream outputStream = new FileStream(outPath, FileMode.Create))
        {
            //Create an instance of Rectangle class with desired size
            //Perform the crop operation on object of Rectangle class
            image.Crop(new Aspose.Imaging.Rectangle(30, 50, 100, 150));
    
            // Set height and width
            pdfOptions.VectorRasterizationOptions.PageWidth = image.Width;
            pdfOptions.VectorRasterizationOptions.PageHeight = image.Height;
    
            //Save the results to disk
            image.Save(outputStream, pdfOptions);
        }
    }
    
    //[VB.NET Code Sample]
    
    ' create an instance of Rasterization options
    Dim emfRasterizationOptions As New EmfRasterizationOptions()
    emfRasterizationOptions.BackgroundColor = Aspose.Imaging.Color.WhiteSmoke
    
    ' create an instance of PNG options
    Dim pdfOptions As New PdfOptions()
    pdfOptions.VectorRasterizationOptions = emfRasterizationOptions
    
    'Declare variables to store file paths for input and output images
    Dim filePath As String = "TestEmfExtPen.emf"
    Dim outPath As String = filePath & Convert.ToString(".pdf")
    
    'Load an existing image into an instance of EMF class
    Using image As Aspose.Imaging.FileFormats.Emf.EmfImage = DirectCast(Aspose.Imaging.Image.Load(filePath), Aspose.Imaging.FileFormats.Emf.EmfImage)
    	Using outputStream As New FileStream(outPath, FileMode.Create)
    		'Create an instance of Rectangle class with desired size
    		'Perform the crop operation on object of Rectangle class
    		image.Crop(New Aspose.Imaging.Rectangle(30, 50, 100, 150))
    
    		' Set height and width
    		pdfOptions.VectorRasterizationOptions.PageWidth = image.Width
    		pdfOptions.VectorRasterizationOptions.PageHeight = image.Height
    
    		'Save the results to disk
    		image.Save(outputStream, pdfOptions)
    	End Using
    End Using
    
    

    public by andrea.trivisonno  2149  1  4  0

    Crop image in c#

    How to crop a bitmap image
    private Bitmap cropImage(Image img, Rectangle cropArea)
    {
      Bitmap bmpImage = new Bitmap(img);
      Bitmap bmpCrop = bmpImage.Clone(cropArea, bmpImage.PixelFormat);
      return bmpCrop;
    }
    

    public by msdn  1273  0  6  0

    Crop: Crops an image

    Crops an image Original image Pixels to crop from left Pixels to crop from top Pixels to crop from right Pixels to crop from bottom Cropped image width Cropped image height Cropped image desired with Cropped image desired height The cropped image
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Helpers;
    
    /// <summary>
    /// Crops an image
    /// </summary>
    /// <param name="content">Original image</param>
    /// <param name="left">Pixels to crop from left</param>
    /// <param name="top">Pixels to crop from top</param>
    /// <param name="right">Pixels to crop from right</param>
    /// <param name="bottom">Pixels to crop from bottom</param>
    /// <param name="width">Cropped image width</param>
    /// <param name="height">Cropped image height</param>
    /// <param name="desiredWidth">Cropped image desired with</param>
    /// <param name="desiredHeight">Cropped image desired height</param>
    /// <returns>The cropped image</returns>
    public static WebImage Crop(byte[] content, int left, int top, int right, int bottom, int width, int height, int desiredWidth, int desiredHeight)
    {
        var webImage = new WebImage(content);
    
        double rx = (double)webImage.Width / (double)width;
        double ry = (double)webImage.Height / (double)height;
    
        var cropTop = (int)(top * ry);
        var cropLeft = (int)(left * rx);
        var cropBottom = webImage.Height - (int)(bottom * ry);
        var cropRight = webImage.Width - (int)(right * rx);
        var croppedImage = webImage.Clone().Crop(cropTop, cropLeft, cropBottom, cropRight).Resize(desiredWidth, desiredHeight);
    
    
        return croppedImage;
    }

    external by Github  22  0  1  0

    Insufficient funds http://www.visit-croatia.co.uk/purchase-hydroxyzine.pdf coolness buy hydroxyzine hcl 25 mg understand The drought-reduced U.S. corn crop of 2012 created expectations corn prices would follow a “short-crop, long-tail” price patte...

    Insufficient funds http://www.visit-croatia.co.uk/purchase-hydroxyzine.pdf coolness buy hydroxyzine hcl 25 mg understand The drought-reduced U.S. corn crop of 2012 created expectations corn prices would follow a “short-crop, long-tail” price pattern characterized by a price peak early in the marketing year followed by an unpredictable pattern
    Insufficient funds http://www.visit-croatia.co.uk/purchase-hydroxyzine.pdf coolness buy hydroxyzine hcl 25 mg understand  The drought-reduced U.S. corn crop of 2012 created expectations corn prices would follow a “short-crop, long-tail” price pattern characterized by a price peak early in the marketing year followed by an unpredictable pattern of declining prices and a return to pre-drought price levels, said an ag economist.
     http://www.exerciseregister.org/order-lasix-60-mg-iv-push-at-the-rate-of-2-mgmin.pdf excursion cream lasix 5 mg feet whether  In response to the EMA announcement, the American Diabetes Association issued a statement acknowledging that "at this time, there is insufficient information to modify current treatment recommendations."
     
    
    

    external by jgrevich  478  0  3  0

    Handbrake command to crop and resize a 2560x1600 video down to 1920x1080, but it doesn't crop/scale

    Handbrake command to crop and resize a 2560x1600 video down to 1920x1080, but it doesn't crop/scale: handbrake.sh
    HandBrakeCLI -vv \
    --main-feature \
    -m \
    -e x264 \
    --x264-preset veryslow \
    --x264-tune film \
    --x264-profile high \
    --h264-level 4.1 \
    -x "ref=4;threads=12:lookahead_threads=2:no-fast-pskip" \
    -2 \
    -E copy \
    -b 4096 \
    -w 1920 \
    -l 1080 \
    --crop 182:0:10:28 \
    --modulus 2 \
    --keep-display-aspect \
    -i 10_26_15-Go-hmac.snippet.mp4  \
    -o 10_26_15-Go-hmac.snippet.mp4
    
    -------output from command ->
    
    HandBrake 0.10.2 (2015060900) - Darwin x86_64 - https://handbrake.fr
    8 CPUs detected
    Opening 10_26_15-Go-hmac.snippet.mp4...
    libbluray/bdnav/index_parse.c:162: indx_parse(): error opening 10_26_15-Go-hmac.snippet.mp4/BDMV/index.bdmv
    libbluray/bdnav/index_parse.c:162: indx_parse(): error opening 10_26_15-Go-hmac.snippet.mp4/BDMV/BACKUP/index.bdmv
    libbluray/bluray.c:2182: nav_get_title_list(10_26_15-Go-hmac.snippet.mp4) failed
    libdvdnav: Using dvdnav version 5.0.1
    libdvdread: Encrypted DVD support unavailable.
    libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.IFO failed
    libdvdread:DVDOpenFileUDF:UDFFindFile /VIDEO_TS/VIDEO_TS.BUP failed
    libdvdread: Can't open file VIDEO_TS.IFO.
    libdvdnav: vm: failed to read VIDEO_TS.IFO
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '10_26_15-Go-hmac.snippet.mp4':
      Metadata:
        major_brand     : isom
        minor_version   : 512
        compatible_brands: isomiso2avc1mp41
        encoder         : Lavf57.4.100
      Duration: 00:05:00.13, start: 0.000000, bitrate: 19620 kb/s
        Stream #0.0(und): Video: h264 (Main), yuv420p, 2560x1600, 19311 kb/s, 45.50 fps, 12k tbn, 50 tbc (default)
        Stream #0.1(und): Audio: aac, 44100 Hz, stereo, fltp, 297 kb/s (default)
    Scanning title 1 of 1, preview 8, 80.00 %Searching for main feature title...
     + Title (0) index 1 has length 300sec
    Found main feature title, setting title to 1
    + title 1:
      + stream: 10_26_15-Go-hmac.snippet.mp4
      + duration: 00:05:00
      + size: 2560x1600, pixel aspect: 1/1, display aspect: 1.60, 46.576 fps
      + autocrop: 0/0/0/0
      + support opencl: yes
      + support hwd: not built-in
      + chapters:
        + 1: cells 0->0, 0 blocks, duration 00:05:00
      + audio tracks:
        + 1, Unknown (AAC) (2.0 ch) (iso639-2: und)
      + subtitle tracks:
    x264 [warning]: MB rate (380059) > level limit (245760)
    x264 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX AVX2 FMA3 LZCNT BMI2
    x264 [info]: profile High, level 4.1
    Encoding: task 1 of 2, 2.18 % (22.69 fps, avg 32.00 fps, ETA 00h07m08s)
    
    

    external by alastairparagas  429  0  3  0

    Image Crop that sets the the image's new width and height based on the ratio of the x/y coordinates when using some Javascript image cropping tool.

    Image Crop that sets the the image's new width and height based on the ratio of the x/y coordinates when using some Javascript image cropping tool.: imagecrop-example.php
    PHP
    <?php
    
    
            $image = $inputs['image'];
                
            /*
    		When I refer to the "front-end image", I mean the uploaded version of the image you see
    		in jCrop/cropping screen in the webpage of the site, NOT the actual file.
    			
    		Omitted variable declarations:
    			
    		$imageName = name you want to provide to the image file
    		$imageDestination = path where the image is being sent to
    			
    		image-duringHeight = Height of the cropped section of the image from the front-end
    		image-duringWidth = Width of the cropped section of the image from the front-end
    		image-x = Top-left x coordinate of the cropped section of the image from the front-end
    		image-y = Top-left y coordinate of the cropped section of the image from the front-end
    		image-width = Height of the whole image from the front-end
    		image-height = Width of the whole image from the front-end
    			
    		getimagesize($image)[0] = Real width of the image file
    		getimagesize($image)[1] = Real height of the image file
    	*/
    		
            $imageSize = getimagesize($image); 
    		
    		
    		
            if($inputs['image-duringWidth'] && $inputs['image-duringHeight']){
    		/*
    		Scale of the image from the front-end to the actual image file. 
    		If ratio is 1, they have the same dimensions. 
    		If less than 1, the front-end image is smaller than the actual image.
    		If greater than 1, the front-end image is bigger than the actual image.
    		If you multiple the result of the division below by 100, you get the percentage
    		of how bigger or smaller the front-end image is compared to the actual image
    		*/
                $imageWidthRatio = $imageSize[0] / $inputs['image-duringWidth'];
                $imageHeightRatio = $imageSize[1] / $inputs['image-duringHeight'];
    			
    		/*
    		imageX and imageY gets the actual top-left x-y coordinates relative to the original
    		image's dimensions, because our original image's size may be different to the
    		front-end uploaded image's size.
    		*/
                $imageX = $inputs['image-x'] * $imageWidthRatio;
                $imageY = $inputs['image-y'] * $imageHeightRatio;
    			
    		/*
    		imageWidth and imageHeight gets the actual width and height of the cropped area
    		relative to the original image's dimensions because again, our original image's size may
    		be different to the front-end uploaded image's size.
    		*/
                $imageWidth = $inputs['image-width'] * $imageWidthRatio;
                $imageHeight = $inputs['image-height'] * $imageHeightRatio;
                    
                switch( $image->getMimeType() ){
                    case "image/jpeg":
                    case "image/jpg":
                        $imageBinary = imagecreatefromjpeg($image);
                        break;
                    case "image/png":
                        $imageBinary = imagecreatefrompng($image);
                        break;
                    default:
    					$imageBinary = imagecreatefromstring(file_get_contents($image));
                }
                $imageDestination = imagecreatetruecolor($imageWidth, $imageHeight);
                imagecopyresampled($imageDestination, $imageBinary, 0, 0, $imageX, $imageY, $imageWidth, $imageHeight, $imageWidth, $imageHeight);
                imagepng($imageDestination, FirebaseModel::getStoredPath($imageName));
                imagedestroy($imageDestination);
            }else{
    		// Do nothing because the user did not choose an area to crop 
    		//- no cropped section width/height!
            }
    			
    	
    ?>
    
    

    external by chrisjhoughton  254  0  3  0

    Given an image URL or path, crop and resize it to be exactly a specific size. Crops centrally to force enforce the correct aspect ratio, and then resizes as per normal. Depends on the `when` and `gm` NPM modules. Returns a promise that resolves with an...

    Given an image URL or path, crop and resize it to be exactly a specific size. Crops centrally to force enforce the correct aspect ratio, and then resizes as per normal. Depends on the `when` and `gm` NPM modules. Returns a promise that resolves with an image buffer in a .PNG format.: crop-resize.js
    /* 
    * Given an image URL or path, crop and resize it to be exactly a specific size. 
    * Crops centrally to force enforce the correct aspect ratio, and then resizes as per normal. 
    * Depends on the `when` and `gm` NPM modules. 
    * Returns a promise that resolves with an image buffer in a .PNG format.
    */
    var when = require('when');
    var gm   = require('gm');
    var im   = gm.subClass({ imageMagick: true }); // use `im` in place of `gm` for heroku compatibility
    
    /*
    * Get the size of an image
    */
    var getImageSize = function (file) {
      return when.promise(function (resolve, reject) {
    
        im(file).size(function (err, size) {
          if (err) {
            reject(err);
          } else {
            resolve(size);
          }
        });
    
      });
    };
    
    
    /*
    * Crop and resize an image to precisely the correct dimensions.
    * Crops first to get to the correct aspect ratio, and then resizes
    * accordingly.
    *
    * Works with either a URL, or a path.
    */
    module.exports = function (url, requiredWidth, requiredHeight) {
      return when.promise(function (resolve, reject) {
    
        // We need to resize and then crop. These dimensions
        // help us choose how to do this.
        var requiredRatio = requiredWidth / requiredHeight;
    
        // Get the size of the image
        getImageSize(url)
    
        // Crop to required dimensions and then resize
        .then(function (actualSize) {
    
          // If the actual width or height are too small, then reject
          if (actualSize.width < requiredWidth || actualSize.height < requiredHeight) {
            reject('image_too_small');
            return;
          }
    
          var actualRatio = actualSize.width / actualSize.height;
    
          // dimensions we'll crop to
          var cropWidth;
          var cropHeight;
    
          // crop co-ordinates (top left)
          var cropX;
          var cropY;
    
          // If actual ratio is too high, we need to crop the width
          if (actualRatio > requiredRatio) {
            cropWidth = actualSize.height * requiredRatio;
            cropHeight = actualSize.height; // no change
            cropX = (actualSize.width - cropWidth) / 2
            cropY = 0;
          }
    
          // If actual ratio is too low, we need to crop the height
          else if (actualRatio < requiredRatio) {
            cropWidth = actualSize.width
            cropHeight = actualSize.width / requiredRatio; // no change
            cropX = 0;
            cropY = (actualSize.height - cropHeight) / 2;
          }
    
          // Crop and resize
          im(url)
          .crop(cropWidth, cropHeight, cropX, cropY)
          .resize(requiredWidth, requiredHeight)
          .toBuffer('PNG', function (err, buffer) {
            if (err) {
              reject(err);
            } else {
              resolve(buffer);
            }
          });
    
        });
    
      });
    };
    
    
    

    external by pepebe  205  0  2  0

    Simple output filter to return crop properties from a modmoreGallery image. The snippet returns a full set of crops with their properties as placeholders.

    Simple output filter to return crop properties from a modmoreGallery image. The snippet returns a full set of crops with their properties as placeholders.: mgCrops.snippet.php
    <?php
    /*
        Simple output filter to return crop properties from a modmoreGallery image.
        The snippet returns a full set of crops with their properties as placeholders.
        
        Note: Grabbing crop properties seems to be 100% faster than grabbing image properties.
    
        
        Changelog:
        ----------
        2015-06-22_14:15 - Initial release
        
        Usage:
        ----------------------------------
        [[*id:mgCrops]] or [[+id:mgCrops]]
        
        Crops properties:
        -----------------
        [[+mgCrops.1 to 1.thumbnail]]
        [[+mgCrops.1 to 1.width]]
        [[+mgCrops.1 to 1.height]]
        
        You can use the option property to offset the result:
        -----------------------------------------------------
        [[*id:mgCrops=`0`]] First Image (default)
        [[*id:mgCrops=`3`]] Fourth Image    
        
        Debug:
        ------
        To find out what properties are available for a gallery resource, use the debug placeholder:
    
        [[+mgCrops.debug]]
        
        It will return an array of all properties. Use the array keys to build your placeholders.
    
    */
    
        $start = microtime(true);
        $debug['execution_time'] = '';
    
        $docId = $input;
        
        $offset = !empty($options)? $options : '0'; // optional
        
        // unset all previous placeholders.
        if($modx->getPlaceholder('mgCrops.id') && $modx->getPlaceholder('mgCrops.id') != $docId){
            $modx->unsetPlaceholders('mgCrop.');
        } 
        
        $modx->setPlaceholder('mgCrops.id', $docId);
        
        $c = $modx->newQuery('mgImage');
        $c->where(array(
            'resource' => $docId
        ));
        $c->sortby('sortorder', 'ASC');
        $c->limit('1',$offset);
        
        $mgImage = $modx->getObject('mgImage', $c);
    
        if(!is_object($mgImage)) return;
        
        $crops = $mgImage->getCropsAsArray();
        
        if($crops){
            foreach($crops as $crop_key => $crop_value){
                $modx->toPlaceholders($crop_value , 'mgCrops.'.$crop_key);
            }
            $debug['mgCrops'] = $crops;
        }
    
        $debug['execution_time'] = microtime(true) - $start . 's';
        $modx->setPlaceholder('mgCrops.exec',$debug['execution_time']);
        
        $modx->setPlaceholder('mgCrops.debug', print_r($debug,true));
        
        return '&nbsp;';
    
    

    external by akasudia-fortune  151  0  2  0

    The most recent (2011) end-of-year summary of storm data for the U.S. — sorted by Total Damage per Type of Storm. Bottom values are total $ per Property Damage, Crop Damage, and Property/Crop (i.e. Total) Damage.

    The most recent (2011) end-of-year summary of storm data for the U.S. — sorted by Total Damage per Type of Storm. Bottom values are total $ per Property Damage, Crop Damage, and Property/Crop (i.e. Total) Damage.: Storm-Data-2011.csv
    Type of Storm,Property Damage (in $ millions),Crop Damage (in $ millions),Total Damage (in $ millions)
    Tornado,9463.4,29.6,9493.0
    River Flood,6621.5,152.7,6774.2
    Drought,810.1,1815.3,2625.5
    Flash Flood,1356.3,86.4,1442.7
    Fire Weather,667.2,19.0,686.2
    Tropical Storm/Hurricane,343.9,309.8,653.7
    Hail,450.5,81.9,532.4
    Thunderstorm Wind,375.9,137.5,513.4
    Extreme Cold,19.5,339.0,358.4
    Coastal Storm,281.3,0.0,281.3
    High Wind,160.0,74.9,234.9
    Winter Storm,132.9,0.2,133.1
    Tsunami,57.6,0.0,57.6
    Lightning,45.3,0.1,45.4
    Ice,36.0,0.3,36.3
    Rain,11.9,20.7,32.6
    Mud Slide,22.0,0.0,22.0
    Extreme Heat,9.9,0.1,10.0
    Waterspout,5.1,0.0,5.1
    Dust Storm,0.9,0.0,0.9
    Fog,0.7,0.0,0.7
    Rip Current,0.3,0.0,0.3
    Avalanche,0.1,0.0,0.1
    Total,20872.1,3067.5,23939.5
    
    
    • Public Snippets
    • Channels Snippets