Tag Archive for image

Generate Thumbnails with all same resolution (Cropped)

find . -maxdepth 1 -iname '*jpg' -exec convert {} -thumbnail x200 -resize '200x<' -resize 50% -gravity center -crop 100x100+0+0 +repage -format jpg -quality 91 thumb/{} ;

source

Generate thumbnail with ImageTool

ImageTool imgTool = new ImageTool()
imgTool.load($1.getBytes())
imgTool.thumbnail(260)
return imgTool.getBytes("JPEG")

source

Fetch a Gravatar Image

<?php
$gravatar_link = '<a href="http://www.gravatar.com/avatar/'" >http://www.gravatar.com/avatar/'</a> . md5($email) . '?s=32';
echo '<img src="' . $gravatar_link . '" alt="gravatar"/>';
?>

source

Create a handwritten signature with a WordPress shortcode

function sc_signature() {
   return '<div id="signature"></div>';
}
add_shortcode('signature', 'sc_signature');

Last, define the style for the #signature id by adding the following code to your style.css:

#signature {
background:url(images/signature.jpg) no-repeat top left;
width:100px;
height:100px;
}

Note: You may have to edit the width and height to fit your image size.

Now, when you’ll want to insert your signature at the end of a post, simply switch WordPress editor to HTML mode and type the following:

[signature]

source

List all sequences (recursively) in a dir

import os, sys
#from sets import Set
path = 'Z:/job/TOTEM/SHOTS/AZ003/Frames/render/character/'
files = os.listdir(path)

finalSeqList = []

def padFrame(frame,pad):
    return '0' * (pad - len(str(frame))) + str(frame)

def seqLS (dirPath):
    files = os.listdir(dirPath)
    for file in files:
        try:
            prefix, frame, suffix = file.split('.')
    
            # build a dictionary of the sequences as {name: frames, suffix}
            #
            # eg beauty.01.tif ... beauty.99.tif  will convert to
            # { beauty : [01,02,...,98,99], tif }
    
            try:
                result[prefix][0].append(frame)
            except KeyError:
                # we have a new file sequence, so create a new key:value pair
                result[prefix] = [[frame],suffix]   
        except ValueError:
            # the file isn't in a sequence, add a dummy key:value pair
            result[file] = file
    
    
    for prefix in result:
        if result[prefix] != prefix:
            frames = result[prefix][0]
            frames.sort()
    
            # find gaps in sequence
            startFrame = int(frames[0])
            endFrame = int(frames[-1])
            pad = len(frames[0])
            idealRange = set(range(startFrame,endFrame))
            realFrames = set([int(x) for x in frames])
            # sets can't be sorted, so cast to a list here
            missingFrames = list(idealRange - realFrames)
            missingFrames.sort()
    
            #calculate fancy ranges
            subRanges = []
            for gap in missingFrames:
                if startFrame != gap:
                    rangeStart = padFrame(startFrame,pad)
                    rangeEnd  = padFrame(gap-1,pad)
                    subRanges.append('-'.join([rangeStart, rangeEnd]))
                startFrame = gap+1
                
            subRanges.append('-'.join([padFrame(startFrame,pad), padFrame(endFrame,pad) ]))
            frameRanges = ','.join(subRanges)
            frameRanges = '[%s]' % (frameRanges)
            suffix = result[prefix][1]
            sortedList.append('.'.join([prefix, frameRanges ,suffix]))
            print ('	' + '.'.join([prefix, frameRanges ,suffix]))
        else: sortedList.append(prefix)
   
    
if __name__ == '__main__':
    if len(sys.argv) > 1:
        path = sys.argv[1]
        
    for root, dirs, files in os.walk(path):
        for curDir in dirs:
            fulldir = os.path.join(root, curDir)
            print 'Scanning : %s' % (fulldir)
            result = {}
            sortedList = []
            seqLS(fulldir)

source

Static images navigation / Image menu

# ==========
# Events
# ==========
lib.events = HMENU
lib.events {
  special = directory
  special.value = {$events.pid}

  1 = TMENU
  1 {
    wrap = <ul>|</ul>
    noBlur = 1

    NO {
      allWrap = <li>|</li>

      stdWrap.cObject = COA
      stdWrap.cObject {
        10 = TEXT
        10.wrap = <img src="uploads/media/|" alt="
        10.data = field:media

        20 = TEXT
        20.wrap = |"
        20.data = field:subtitle

        30 = TEXT
        30.wrap = title="|" />
        30.data = field:subtitle
      }
    }
  }
}

source

get_image

// get and return images for empty images
function get_image($url)
{
	$image = get_headers($url,1);
	if($image['content-length'] > 807) return $url;
	else return base_assets().'images/footer_logo.png';
}

source

Basic JavaScript Image Fading

function fade(step) {
    var imgs = document.getElementsByTagName("img");
    step = step || 0;
    imgs[1].style.opacity = step/100;
    imgs[1].style.filter = "alpha(opacity=" + step + ")";
    step += 2;
    if (step <= 100) {
        setTimeout(function() {
            fade(step);
        }, 1);
    }
}

source

Fluid images

//usage
//simple
addLoadEvent(function() {
	imgSizer.collate();
});

//limiting the scope
addLoadEvent(function() {
     if (document.getElementById && document.getElementsByTagName) {
          var aImgs = document.getElementById("#content").getElementsByTagName("img");
          imgSizer.collate(aImgs);
     }
});

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}


//code
var imgSizer = {
	Config : {
		imgCache : []
		,spacer : "/path/to/your/spacer.gif"
	}

	,collate : function(aScope) {
		var isOldIE = (document.all && !window.opera && !window.XDomainRequest) ? 1 : 0;
		if (isOldIE && document.getElementsByTagName) {
			var c = imgSizer;
			var imgCache = c.Config.imgCache;

			var images = (aScope && aScope.length) ? aScope : document.getElementsByTagName("img");
			for (var i = 0; i < images.length; i++) {
				images[i].origWidth = images[i].offsetWidth;
				images[i].origHeight = images[i].offsetHeight;

				imgCache.push(images[i]);
				c.ieAlpha(images[i]);
				images[i].style.width = "100%";
			}

			if (imgCache.length) {
				c.resize(function() {
					for (var i = 0; i < imgCache.length; i++) {
						var ratio = (imgCache[i].offsetWidth / imgCache[i].origWidth);
						imgCache[i].style.height = (imgCache[i].origHeight * ratio) + "px";
					}
				});
			}
		}
	}

	,ieAlpha : function(img) {
		var c = imgSizer;
		if (img.oldSrc) {
			img.src = img.oldSrc;
		}
		var src = img.src;
		img.style.width = img.offsetWidth + "px";
		img.style.height = img.offsetHeight + "px";
		img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
		img.oldSrc = src;
		img.src = c.Config.spacer;
	}

	// Ghettomodified version of Simon Willison's addLoadEvent() -- <a href="http://simonwillison.net/2004/May/26/addLoadEvent/" >http://simonwillison.net/2004/May/26/addLoadEvent/</a>
	,resize : function(func) {
		var oldonresize = window.onresize;
		if (typeof window.onresize != 'function') {
			window.onresize = func;
		} else {
			window.onresize = function() {
				if (oldonresize) {
					oldonresize();
				}
				func();
			}
		}
	}
}

source

Integrate Adobe Photoshop Mobile inside your Android application

// code inside an Activity method
Uri imageToEditUri = … // uri of image to edit
String imageToEditMimeType = … // must be of type “image/*”
Intent launchEditor = new Intent();
launchEditor.setAction(Intent.ACTION_EDIT);
launchEditor.setDataAndType(imageToEditUri, imageToEditMimeType);

try
{
    // start the editor activity
    startActivityForResult(launchEditor, LAUNCH_EDITOR);
}
catch (ActivityNotFoundException e)
{
    // Handle error condition. Correct version of
    // Photoshop.com Mobile not installed?
}

source