Latest 100 public
snipts » image
showing 1-20 of 33 snipts for image
-
∞ convert pdf to png with a background color at 300 dpi
inkscape -d 300 -D -z -e moments.png -b '#FFFFFF' moments.pdf -
∞ Batch resize images
mogrify -resize <800>x<600> <*.ext>
-
∞ image link con target _blank
<? $img_path = "images/arr_leggi_blu.gif"; $link_path = "node/47"; $theme_name = 'pmsth'; $options = array( 'attributes' => array( 'target' => '_blank', ), 'html' => true, ); $img = theme('image', drupal_get_path('theme', $theme_name). "/$img_path"); print l($img, $link_path, $options); ?>
-
∞ create CAPTCHA
<?php // download jpgraph http://www.aditus.nu/jpgraph/ ini_set('include_path', ini_get('include_path').';D:\xmapp\xampp\htdocs\php\jpgraph-3.0.7\src'); require_once "jpgraph_antispam.php"; $spam = new AntiSpam(); //$chars = $spam->Rand(6); $spam->set("mystring"); $spam->Stroke(); ?>
-
∞ prevent the hotlinking of images
<?php // setting in http.conf file. SetEnvIfNoCase Referer "^http://www\.sitepoint\.com/" locally_linked=1 SetEnvIfNoCase Referer "^http://sitepoint\.com/" locally_linked=1 SetEnvIfNoCase Referer "^$" locally_linked=1 <FilesMatch "\.(gif|png|jpe?g)$"> Order Allow,Deny Allow from env=locally_linked </FilesMatch> ?>
-
∞ add a watermark to an image
<?php // text watermark $image = imagecreatefromjpeg('test.jpg'); $color = imagecolorallocate($image, 68, 68, 68); imagestring($image, 5, 90, 0, "Abbey '07", $color); header('Content-Type: image/jpg'); imagejpeg($image); // image watermark $image = imagecreatefromjpeg('test.jpg'); $iWidth = imagesx($image); $watermark = imagecreatefrompng('watermark.png'); $wmWidth = imagesx($watermark); $wmHeight = imagesy($watermark); $xPos = $iWidth - $wmWidth; imagecopymerge($image, $watermark, $xPos, 0, 0, 0,$wmWidth, $wmHeight, 100); header('Content-Type: image/jpg'); imagepng($image); ?>
-
∞ how php thumbnail a image?
<?php $sourceImage = 'source.jpg'; $thumbWidth = 200; $thumbHeight = 200; $original = imagecreatefromjpeg($sourceImage); $dims = getimagesize($sourceImage); if( $dims[0] > $dims[1] ) { $thumbHeight = floor( $dims[1]*( $thumbWidth/$dims[0]) ); }else if( $dims[0] < $dims[0] ) { $thumbWidth = floor( $dims[0]*($thumbHeight/$dims[1]) ); } $thumb = imagecreatetruecolor($thumbWidth,$thumbHeight); imagecopyresampled( $thumb, $original, 0, 0, 0, 0,$thumbWidth, $thumbHeight, $dims[0], $dims[1] ); header( "Content-type: image/jpeg" ); imagejpeg( $thumb ); ?>
-
∞ Magicfields duplicate image fields
<?php $images = getFieldOrder('gallery_pic'); foreach ($images as $image) { $my_image_url = get('gallery_pic',1,$image); //print $my_image_url; ?> <li> <a href="<?php echo $my_image_url; ?>" rel="overlay"> <?php // $title = get_the_title(); $img_phpthumb = array ("w" => 56, "h" => 56, "zc" => 1); $img_htm = array("alt" => "event thumbnail", "class" => "left event-thumb" ); echo gen_image('gallery_pic',1,$image,$img_phpthumb,$img_htm); ?> </a> </li> <?php } ?>
-
∞ IMG Hover Opacity
a:hover img { opacity: .75; }
-
∞ Magicfields gen_image
<?php $title = get_the_title(); $img_phpthumb = array ("w" => 189, "h" => 130, "zc" => 1); $img_htm = array("alt" => "event thumbnail", "class" => "left event-thumb", "title" => $title ); echo gen_image('event_thumbnail',1,1,$img_phpthumb,$img_htm); ?>
-
∞ Toggle child table row with button in parent table row
//html markup <tr class="note_parent"> <td><a href="#"><img src="your toggle image" alt="toggle" style="display:none;" /></a></td> </tr> <tr class="add_note" style="display:none;"> <td>hidden content</td> </tr> //jQuery functions $("tr.note_parent").hover(function() { $(this).find("a img").css("display", "inline"); }, function() { $(this).find("a img").css("display", "none"); }); $("tr.note_parent a img").click(function() { $(this).parents("tr:first").next("tr.add_note").css("display", "table-row"); return false; });
-
∞ 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', $theme_name). "/$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"; ?>


