Public
snipts » image
showing 1-20 of 23 snipts for image
-
∞ Hi Quality Image Resizing in C#.NET
using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; using System.IO; public class ImageProcessing { public static Bitmap ResizeImage(Bitmap image, int pixelWidth, int pixelHeight, int compressionQuality) { // Bully compression quality in range 1 to 100 if (compressionQuality < 1) { compressionQuality = 1; } if (compressionQuality > 100) { compressionQuality = 100; } Bitmap tempImage = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb); tempImage.SetResolution(image.HorizontalResolution, image.VerticalResolution); Graphics g = Graphics.FromImage(tempImage); g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.SmoothingMode = SmoothingMode.HighQuality; g.DrawImage(image, new Rectangle(0, 0, pixelWidth, pixelHeight), new Rectangle(0, 0, image.Width, image.Height), GraphicsUnit.Pixel); g.Dispose(); ImageCodecInfo jpegCodec = null; foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageEncoders()) { if (codec.MimeType == "image/jpeg") { jpegCodec = codec; } } EncoderParameters encoderParams = new EncoderParameters(1); EncoderParameter quality = new EncoderParameter(Encoder.Quality, (long)compressionQuality); encoderParams.Param[0] = quality; Stream imageStream = new MemoryStream(); tempImage.Save(imageStream, jpegCodec, encoderParams); Bitmap finalImage = new Bitmap(imageStream); // Clean up resources g.Dispose(); tempImage.Dispose(); return finalImage; } }
-
∞ image link
<? $img_path = "/images/arr_leggi_blu.gif"; $link_path = "node/47"; $theme_name = 'pmsth'; $img = theme('image', drupal_get_path('theme', 'pmsth'). $img_path); print l($img, $link_path, array('html' => true)); ?>
-
∞ image
<? $path = "/images/arr_leggi_blu.gif"; $theme_name = 'pmsth'; print theme('image', drupal_get_path('theme', $theme_name). $path); ?>
-
∞ ASCII image via PHP
<?php function image2ascii( $image ) { // return value $ret = ''; // open the image $img = ImageCreateFromJpeg($image); // get width and height $width = imagesx($img); $height = imagesy($img); // loop for height for($h=0;$h<$height;$h++) { // loop for height for($w=0;$w<=$width;$w++) { // add color $rgb = ImageColorAt($img, $w, $h); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> <img src='http://www.sastgroup.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> & 0xFF; $b = $rgb & 0xFF; // create a hex value from the rgb $hex = '#'.str_pad(dechex($r), 2, '0', STR_PAD_LEFT).str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT); // now add to the return string and we are done if($w == $width) { $ret .= ''; } else { $ret .= '<span style="color:'.$hex.';">#</span>'; } } } return $ret; } //ESEMPIO APPLICATO // an image to convert $image = 'test.jpg'; // do the conversion $ascii = image2ascii( $image ); // and show the world echo $ascii; ?>
-
∞ Random Image
<?php $folder = 'images/'; $extList = array(); $extList['gif'] = 'image/gif'; $extList['jpg'] = 'image/jpeg'; $extList['jpeg'] = 'image/jpeg'; $extList['png'] = 'image/png'; $img = null; if (isset($_GET['img'])) { $imageInfo = pathinfo($_GET['img']); if (isset($extList[strtolower($imageInfo['extension'])]) && file_exists($folder.$imageInfo['basename'])) $img = $folder.$imageInfo['basename']; } else { $fileList = array(); $handle = opendir($folder); while (false !== ($file = readdir($handle))) { $file_info = pathinfo($file); if (isset( $extList[ strtolower( $file_info['extension'])])) { $fileList[] = $file; } } closedir($handle); if (count($fileList) > 0) { $imageNumber = time() % count($fileList); $img = $folder.$fileList[$imageNumber]; } } if ($img!=null) { $imageInfo = pathinfo($img); $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ]; header($contentType); readfile($img); } else { if (function_exists('imagecreate')) { header ("Content-type: image/png"); $im = @imagecreate (100, 100) or die ("Cannot initialize new GD image stream"); $background_color = imagecolorallocate ($im, 255, 255, 255); $text_color = imagecolorallocate ($im, 0,0,0); imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color); imagepng ($im); imagedestroy($im); } }
-
∞ 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 . "\" />";
-
∞ jQuery hover image swap
<script type="text/javascript"> $(function() { $("img.swap").hover( function () { $(this).attr("src", $(this).attr("src").replace(/.jpg/, "_swap.jpg")); $(this).attr("src", $(this).attr("src").replace(/.gif/, "_swap.gif")); }, function () { $(this).attr("src", $(this).attr("src").replace(/_swap.jpg/, ".jpg")); $(this).attr("src", $(this).attr("src").replace(/_swap.gif/, ".gif")); } ); }); </script>
-
∞ get image header information
identify -verbose
-
∞ Grab image files from directory
<?php $files=glob("path/to/directory/*.jpg*", GLOB_NOSORT); $firstfile=reset($files); echo "<ul id=\"rotator\">\n"; foreach($files as $file){ if($firstfile==$file){ echo "\t<li class=\"show\"><a href=\"#\"><img src=\"".$file."\" width=\"\" height=\"\" alt=\"\" /></a></li>\n"; }else{ echo "\t<li><a href=\"#\"><img src=\"".$file."\" width=\"\" height=\"\" alt=\"\" /></a></li>\n"; } } echo "</ul>\n"; ?>
-
∞ Fix for mir image replacement (IE6)
.mir {letter-spacing : -1000em; text-indent : -999em; overflow : hidden;}
-
∞ PNG transparent 1x1px generator
<?php /***************************************************************** * Script for automatic generation of one pixel * alpha-transparent images for non-RGBA browsers. * @author Lea Verou * @version 1.0 beta * Licensed under a MIT license *****************************************************************/ ######## SETTINGS ############################################################## /** * Enter the directory in which to store cached color images. * This should be relative and SHOULD contain a trailing slash. * The directory you specify should exist and be writeable (CHMOD 666 or 777). * If you want to store the pngs at the same directory, leave blank (''). */ define('COLORDIR', 'rgba/'); /** * If you requently use a color with varying alphas, you can name it * below, to save you some typing and make your CSS easier to read. */ $color_names = array( 'white' => array(255,255,255), 'black' => array(0,0,0) // , 'mycolor' => array(red value, green value, blue value) ); /** * If you don't want the generated pngs to be stored in the server, set the following to * false. This is STRONGLY NOT RECOMMENDED. It's here only for testing/debugging purposes. */ define('CACHEPNGS', true); ######## NO FURTHER EDITING, UNLESS YOU REALLY KNOW WHAT YOU'RE DOING ########## $dir = substr(COLORDIR,0,strlen(COLORDIR)-1); if(!is_writable($dir)) { die("The directory '$dir' either doesn't exist or isn't writable."); } $rgb = $color_names[$_GET['name']]; $red = is_array($rgb)? $rgb[0] : intval($_GET['r']); $green = is_array($rgb)? $rgb[1] : intval($_GET['g']); $blue = is_array($rgb)? $rgb[2] : intval($_GET['b']); $alphaurl = $_GET['a']; // "A value between 0 and 127. 0 indicates completely opaque while 127 indicates completely transparent." // http://www.php.net/manual/en/function.imagecolorallocatealpha.php $alpha = intval(127 - 127 * ($alphaurl / 100)); // Does it already exist? $filepath = COLORDIR . "r{$red}_g{$green}_b{$blue}_a{$alphaurl}.png"; if(/*CACHEPNGS and */file_exists($filepath)) { $url = "http://{$_SERVER['HTTP_HOST']}/{$filepath}"; header("Status: 301"); die(header("Location: {$url}")); } else { // Send headers header('Content-Type: image/png'); header("Expires: ".gmdate("D, d M Y H:i:s", strtotime('+5 years'))." GMT"); $img = @imagecreatetruecolor(1,1) or die('Cannot Initialize new GD image stream'); // This is to allow the final image to have actual transparency // http://www.php.net/manual/en/function.imagesavealpha.php imagealphablending($img, false); imagesavealpha($img, true); // Allocate our requested color $color = imagecolorallocatealpha($img, $red, $green, $blue, $alpha); // Fill the image with it imagefill($img,0,0,$color); // Save the file imagepng($img,$filepath,0,NULL); // Serve the file imagepng($img); flush(); // Free up memory imagedestroy($img); } ?>
-
∞ Fullscreen image scaling using ActionScript 2
import mx.transitions.Tween; import mx.transitions.easing.*; var stageListener:Object=new Object(); stageListener.onResize=function(){ position(); }; Stage.align="TL"; Stage.scaleMode="noScale"; Stage.addListener(stageListener); function position() { // Find new value of stage size var W:Number = Stage.width; var H:Number = Stage.height; // Find center of stage var centerX:Number = W/2; var centerY:Number = H/2; background_mc._x = centerX; background_mc._y = centerY; background_mc.target_mc._x = -_global.BGW/2; background_mc.target_mc._y = -_global.BGH/2; var imageRatio:Number; var imageXRatio = W/_global.BGW; var imageYRatio = H/_global.BGH; if (imageXRatio>imageYRatio) { imageRatio = imageXRatio; } else { imageRatio = imageYRatio; } // Make the bg image go fullscreen background_mc._xscale = background_mc._yscale=imageRatio*100; } // Function for smoothing resizable bitmaps function smoothImageLoad(imgURL, targetMovie) { var i = 0; do { i++; } while (eval("_root.smoothImageLoadTemp"+i) != undefined); tmc = targetMovie.createEmptyMovieClip("smoothImageLoadTemp"+i, targetMovie.getNextHighestDepth()); tmc.createEmptyMovieClip("ti",tmc.getNextHighestDepth()); tmc.tm = targetMovie; with (tmc) { tmcl = new MovieClipLoader(); tmcl.onLoadComplete = function() { var fadeBG:Tween = new Tween(targetMovie, "_alpha", None.easeOut, 0, 100, 1, true); ti.onEnterFrame = function() { pixelData = new flash.display.BitmapData(ti._width, ti._height); _global.BGW = ti._width; _global.BGH = ti._height; pixelData.draw(ti); tm.attachBitmap(pixelData,1,true,true); tm.smoothImageLoadComplete(); _parent._parent._parent.position(); removeMovieClip(ti._parent); }; }; tmcl.loadClip(imgURL,tmc.ti); } } smoothImageLoad("image.jpg",background_mc.target_mc);
-
∞ 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
-
∞ Simple Image Loader
var loader:MovieClipLoader = new MovieClipLoader(); this.createEmptyMovieClip("MyImageContainer",1); loader.loadClip("image1.jpg",MyImageContainer);
-
∞ Image Rollover Borders
/*Inner Borders*/ #example-one a img, #example-one a { border: none; overflow: hidden; float: left; } #example-one a:hover { border: 3px solid black; } #example-one a:hover img { margin: -3px; } /*Outer Borders*/ #example-two a img, #example-two a { border: none; float: left; } #example-two a { margin: 3px; } #example-two a:hover { outline: 3px solid black; }
-
∞ .Code.JavaScript.Core.Icon.Bare
Icon=function(){ this.list=new Array(); this.root; this.fold; this.name; this.type; this.last; this.load=function(){ for(var i=0;i<this.last;i++){ var j=i*6; this.list[i]=new Image(); this.list[i].src=''+this.root+this.fold+j.toString()+this.name+'.'+this.type; } }; this.init=function(){ if(this.root&&this.fold&&this.name&&this.type&&this.last){ this.load(); } } //this.face=new Face(); }
-
∞ :hover background color change
.class img { background: #ededed; } .class:hover img { background: #dcdcdc; }
-
∞ nav background image
url(images/nav/nav_bg.gif) repeat-x bottom left;
-
∞ Better Image Scaling and Resampling in Internet Explorer
/* * http://acidmartin.wordpress.com/2009/01/05/better-image-scaling-and-resampling-in-internet-explorer/ */ img { -ms-interpolation-mode: bicubic; }
-
∞ 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; }



Practical Web 2.0 Applications with PHP