Sign up to create your own snipts, or login.

Public snipts » resize The latest public resize snipts.

showing 1-12 of 12 snipts for resize
  • Function to resize a JPEG image
    <?php
      function resize_image($original_image_file_name, $resized_image_file_name, $width, $height, $quality)
      {
        $new_image = imagecreatetruecolor($width, $height);
        $src_image = imagecreatefromjpeg($original_image_file_name);
    
        imagecopyresized($new_image, $src_image, 0, 0, 0, 0, $width, $height, imagesx($src_image), imagesy($src_image));
        imagejpeg($new_image, $resized_image_file_name, $quality);
    
        return $resized_image_file_name;
      }
    ?>
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Nov 03, 2009 at 4:38 a.m. EST
  • Bulk resize a set of JPEG images
    # The following packages are needed for this to work:
    # djpeg (libjpeg-progs)
    # cjpeg (libjpeg-progs)
    # netpbm
    
    ls *.jpg | while read F; do echo "Shrinking $F"; djpeg $F | pnmscale 0.63 | cjpeg -quality 100 > small/$F; done
    
    # Another way to perform the same operation is this (original files will be overwritten):
    ls *.jpg | while read F; do echo "Shrinking $F"; mogrify -resize 63% $F; done
    

    copy | embed

    0 comments - tagged in  posted by d1s4st3r on Aug 24, 2009 at 3:21 p.m. EDT
  • Automatically resize an image to max width/height and keep aspect ratio.
            $image = "directory/imagename.ext"; // Location/name of image
            $max_width = "250"; // Max width to display image
            $max_height = "250"; // Max height to display image
             
            list($width, $height) = getimagesize($image);
            $scale = min($max_width/$width, $max_height/$height);
             
            if ($scale < '1') {
                $scale_width = floor($scale * $width);
                $scale_height = floor($scale * $height);
            } else {
                $scale_width = $width;
                $scale_height = $height;
            }
             
            echo "
            <img border=\"0\" src=\"directory/imagename.ext\" width=\"" . $scale_width . "\" height=\"" . $scale_height . "\" />";
    

    copy | embed

    0 comments - tagged in  posted by Webline on Aug 16, 2009 at 11:00 a.m. EDT
  • scale and crop an image to best fit a defined set of dimensions
    function autoCrop($file, $height, $width){
    
         //load the image file
    
         $img = false;
    
         $img = imagecreatefromjpeg($file);
    
         //quit if not loaded
    
         if(!$img){
    
              return false;
    
         }
    
         //get the image dimensions
    
         $curr = @getimagesize($file);
    
     
         $perc_w = $width / $curr[0];
    
         $perc_h = $height / $curr[1];
    
     
    
         if(($width > $curr[0]) || ($height > $curr[1])){
    
              return;
    
         }
    
     
    
         if($perc_h > $perc_w){
    
              //taller
    
              $width = $width;
    
              $height = round($curr[1] * $perc_w);
    
         } else {
    
              //wider
    
              $height = $height;
    
              $width = round($curr[0] * $perc_h);
    
         }
    
         //output
    
         $nwimg = imagecreatetruecolor($width, $height);
    
         imagecopyresampled($nwimg, $img, 0, 0, 0, 0, $width, $height, $curr[0], $curr[1]);
    
         imagejpeg($nwimg, $file);
    
     
    
         imagedestroy($nwimg);
    
         imagedestroy($img);
    
     
    
    }
    

    copy | embed

    0 comments - tagged in  posted by damonky on Jul 24, 2009 at 4:28 a.m. EDT
  • simple flash resize
    import flash.external.*;
    
    butt.addEventListener(MouseEvent.MOUSE_OVER, scrPlayDOWN);
    function scrPlayDOWN(event:MouseEvent = null):void {
    	var RESIZE_CONTAINER:XML = new XML(<script><![CDATA[
    					function(height) {
    						var objNode = document.getElementById('flashid');
    						objNode.style.height = 300;
    					}]]></script>);
    
    	ExternalInterface.call(RESIZE_CONTAINER);
    }
    
    butt.addEventListener(MouseEvent.MOUSE_OUT, scrPlayUP);
    function scrPlayUP(event:MouseEvent = null):void {
    		var RESIZE_CONTAINER:XML = new XML(<script><![CDATA[
    					function(height) {
    						var objNode = document.getElementById('flashid');
    						objNode.style.height = 100;
    					}]]></script>);
    	ExternalInterface.call(RESIZE_CONTAINER);
    }
    

    copy | embed

    0 comments - tagged in  posted by p0d04Va on Apr 10, 2009 at 7:34 a.m. EDT
  • Bo po co rozszerzy? i u?y? strcpy...
    void Person::DodajKomentarz(const char *Komentarz)
    {   if ( Notatka == NULL )
        {   char *wsk = (char*)Komentarz,*wsk2;
            int Size=1;
            while ( *(wsk++) != '\0' ) Size++;
            Notatka = new char[Size];
            wsk = (char*)Komentarz;
            wsk2= Notatka;
            while ( *wsk != '\0' ) *(wsk2++) = *(wsk++);
            *wsk2 = '\0';
        }
        else
        {   char *wsk = (char*)Komentarz;
            char *owsk = Notatka;
            char *nwsk;
            int OldSize = 0;
            while ( *(owsk++) != '\0' ) OldSize++;
            int Size = OldSize;
            while ( *(wsk++) != '\0' ) Size++;
            Size++;
            char *Temp = new char[Size];
            nwsk = Temp;
            wsk = (char*)Komentarz;
            owsk = Notatka;
            while ( *owsk != '\0' ) *(nwsk++) = *(owsk++);
            while ( *wsk != '\0' ) *(nwsk++) = *(wsk++);
            *nwsk = '\0';
            delete[] Notatka;
            Notatka = Temp;
            Temp = NULL;
        }
    }
    

    copy | embed

    0 comments - tagged in  posted by tiraeth on Apr 01, 2009 at 2:14 p.m. EDT
  • RIMAGE - ImageMagick Hack with Mogrify
    #!/bin/bash
    #
    # /usr/bin/rimage: Cria thumbnails a partir de uma imagem png
    #
    # Criado por Lucas Salies Brum aka sistematico <sistematico@gmail.com>
    # Criado em -> 02/04/2009 @ 20:36:59 
    # Última atualização -> 02/04/2009 @ 21:12:58  
    
    if [ ! "$(ls *.png)" ]; then
    	echo "ERRO: Nenhum arquivo png encontrado!"
    	exit 0
    fi	
    
    if [ "$#" -lt 1 ]; then
        for arquivo in $( ls *.png )
        do
            let "num += 1"
            old=$arquivo
        	new=thumb-${arquivo}
        	cp $old $new
        	echo "Reduzindo $old para $new"
        	sleep 1
        	mogrify -resize 20% $new        	
        done
    elif [ "$(echo $1 | rev | cut -d . -f 1)" == "gnp" ]; then
       	if [ ! -f "$1" ]; then
        	echo "ERRO: O arquivo $1 não existe!"
       		exit 0
       	fi	
        old=$1
    	new=thumb-${1}
    	cp $old $new
    	echo "Reduzindo $old para $new"
    	sleep 1
    	mogrify -resize 20% $new
    else 
        echo "usage: rimage image.png"
        echo "or"
        echo "rimage"
        exit 0
    fi
    

    copy | embed

    0 comments - tagged in  posted by sistematico on Mar 26, 2009 at 10:48 p.m. EDT
  • batch resize all JPGs in a folder with output to a subfolder
    mogrify -size 800x600 -path ./resized -monitor ./*.jpg 
    

    copy | embed

    0 comments - tagged in  posted by zerolab on Mar 08, 2009 at 9:12 p.m. EDT
  • this document resizes the text depending on the wiindow size
    <!-- this document resizes the text depending on the wiindow size -->
    
    
    
    <script type="text/javascript"> 
    function checkBrowserWidth()
    {
    var theWidth = getBrowserWidth();
    
    if (theWidth > 1200)
    			{
    			document.getElementsByTagName("body").item(0).style.fontSize='100%';
    		}
    	else { 
    
    if (theWidth > 1000)
    			{
    			document.getElementsByTagName("body").item(0).style.fontSize='87%';
    		}
    	else { 
    	if (theWidth > 920)
    			{
    			document.getElementsByTagName("body").item(0).style.fontSize='81%';
    		}
    	else { 
    		if (theWidth > 840)
    			{
    			document.getElementsByTagName("body").item(0).style.fontSize='76%';
    			}
    		else { 
    			if (theWidth > 760)
    				{
    				document.getElementsByTagName("body").item(0).style.fontSize='69%';
    				}
    			else { 
    				document.getElementsByTagName("body").item(0).style.fontSize='62%';
    				}
    			}
    		}
    	}
    }
    }
    
    function getBrowserWidth()
    {
    	if (window.innerWidth)
    	{
    		return window.innerWidth;
    	}
    	else if (document.documentElement && document.documentElement.clientWidth != 0)
    	{
    		return document.documentElement.clientWidth;
    	}
    	else if (document.body)
    	{
    		return document.body.clientWidth;
    	}
    	
    	return 0;
    }
    
    </script>
    
    
    <!-- this should be placed at or near the foot of the document -->
    
    <script type="text/javascript"> 
    checkBrowserWidth();
    
    window.onresize = checkBrowserWidth;
    </script>
    

    copy | embed

    0 comments - tagged in  posted by thejames on Dec 23, 2008 at 12:23 p.m. EST
  • Proportional image resizing
    function resize_image( $file, $width = 0, $height = 0, $proportional = false, $output = 'file', $delete_original = true )
    {
    	if ( $height <= 0 && $width <= 0 ) return false;
    
    	$info = getimagesize($file);
    	$image = '';
    
    	$final_width = 0;
    	$final_height = 0;
    	list($width_old, $height_old) = $info;
    
       if ($proportional) {
    		   if ($width == 0) $factor = $height/$height_old;
    		   elseif ($height == 0) $factor = $width/$width_old;
    		   else $factor = min ( $width / $width_old, $height / $height_old);
    
    		   $final_width = round ($width_old * $factor);
    		   $final_height = round ($height_old * $factor);
       } else {
    		   $final_width = ( $width <= 0 ) ? $width_old : $width;
    		   $final_height = ( $height <= 0 ) ? $height_old : $height;
       }
    
       switch ($info[2]) {
    		   case IMAGETYPE_GIF:
    				   $image = imagecreatefromgif($file);
    		   break;
    		   case IMAGETYPE_JPEG:
    				   $image = imagecreatefromjpeg($file);
    		   break;
    		   case IMAGETYPE_PNG:
    				   $image = imagecreatefrompng($file);
    		   break;
    		   default:
    				   return false;
       }
    
       $image_resized = imagecreatetruecolor( $final_width, $final_height );
    
       if(($info[2] == IMAGETYPE_GIF) || ($info[2] == IMAGETYPE_PNG)) {
    		   $trnprt_indx = imagecolortransparent($image);
    
    		   // If we have a specific transparent color
    		   if($trnprt_indx >= 0) {
    
    				   // Get the original image's transparent color's RGB values
    				   $trnprt_color    = imagecolorsforindex($image, $trnprt_indx);
    
    				   // Allocate the same color in the new image resource
    				   $trnprt_indx    = imagecolorallocate($image_resized, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
    
    				   // Completely fill the background of the new image with allocated color.
    				   imagefill($image_resized, 0, 0, $trnprt_indx);
    
    				   // Set the background color for new image to transparent
    				   imagecolortransparent($image_resized, $trnprt_indx);
    
    
    		   }
    		   // Always make a transparent background color for PNGs that don't have one allocated already
    		   elseif ($info[2] == IMAGETYPE_PNG) {
    
    				   // Turn off transparency blending (temporarily)
    				   imagealphablending($image_resized, false);
    
    				   // Create a new transparent color for image
    				   $color = imagecolorallocatealpha($image_resized, 0, 0, 0, 127);
    
    				   // Completely fill the background of the new image with allocated color.
    				   imagefill($image_resized, 0, 0, $color);
    
    				   // Restore transparency blending
    				   imagesavealpha($image_resized, true);
    		   }
       }
    
       imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
    
       if($delete_original) @unlink($file);
    
       switch (strtolower($output)) {
    		   case 'browser':
    				   $mime = image_type_to_mime_type($info[2]);
    				   header("Content-type: $mime");
    				   $output = NULL;
    		   break;
    		   case 'file':
    				   $output = $file;
    		   break;
    		   case 'return':
    				   return $image_resized;
    		   break;
    		   default:
    		   break;
       }
    
       switch ($info[2]) {
    		   case IMAGETYPE_GIF:
    				   imagegif($image_resized, $output);
    		   break;
    		   case IMAGETYPE_JPEG:
    				   imagejpeg($image_resized, $output);
    		   break;
    		   case IMAGETYPE_PNG:
    				   imagepng($image_resized, $output);
    		   break;
    		   default:
    				   return false;
       }
    
       return true;
    }
    

    copy | embed

    0 comments - tagged in  posted by evansims on Dec 20, 2008 at 7:39 p.m. EST
  • Resize Icons
    ## Convert all icons in current directory
    ## to 48x48, overwriting the old files.
    
    for icon in *; do convert "$icon" -resize 48x48 ./"$icon"; done
    
    
    ## Convert all icons in current directory to 16x16,
    ## placing the new files in a directory within the current directory.
    
    for icon in *; do convert "$icon" -resize 16x16 ./16x16/"$icon"; done
    

    copy | embed

    0 comments - tagged in  posted by lynng on Dec 18, 2008 at 7:02 p.m. EST
  • Resize a upload image
    <?php
    
    function Resize($Dir, $Image, $NewDir, $NewImage, $MaxWidth, $MaxHeight, $Quality)
    {
        list($ImageWidth, $ImageHeight, $TypeCode) = getimagesize($Dir . $Image);
        $ImageType = ($TypeCode == 1 ? "gif":($TypeCode == 2 ? "jpeg":($TypeCode == 3 ?
            "png":false)));
        $CreateFunction = "imagecreatefrom" . $ImageType;
        $OutputFunction = "image" . $ImageType;
        if ($ImageType)
        {
            $Ratio = ($ImageHeight / $ImageWidth);
            $ImageSource = $CreateFunction($Dir . $Image);
            if ($ImageWidth > $MaxWidth || $ImageHeight > $MaxHeight)
            {
                if ($ImageWidth > $MaxWidth)
                {
                    $ResizedWidth = $MaxWidth;
                    $ResizedHeight = $ResizedWidth * $Ratio;
                }
                else
                {
                    $ResizedWidth = $ImageWidth;
                    $ResizedHeight = $ImageHeight;
                }
                if ($ResizedHeight > $MaxHeight)
                {
                    $ResizedHeight = $MaxHeight;
                    $ResizedWidth = $ResizedHeight / $Ratio;
                }
                $ResizedImage = imagecreatetruecolor($ResizedWidth, $ResizedHeight);
                imagecopyresampled($ResizedImage, $ImageSource, 0, 0, 0, 0, $ResizedWidth, $ResizedHeight,
                    $ImageWidth, $ImageHeight);
            }
            else
            {
                $ResizedWidth = $ImageWidth;
                $ResizedHeight = $ImageHeight;
                $ResizedImage = $ImageSource;
            }
            $OutputFunction($ResizedImage, $NewDir . $NewImage, $Quality);
            return true;
        }
        else
            return false;
    }
    
    ?>
    

    copy | embed

    0 comments - tagged in  posted by borisegx on Dec 14, 2008 at 9:11 p.m. EST
Sign up to create your own snipts, or login.