Tag Archive for image

Resize image

function crear_miniatura($name,$filename,$new_w,$new_h,$carpeta){
	$system=explode(".",$_FILES['Filedata']['name']);
	if (preg_match("/jpg|jpeg|JPG|JPEG/",$system[1])){$src_img=imagecreatefromjpeg($name);}
	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
	if (preg_match("/gif/",$system[1])){$src_img=imagecreatefromgif($name);}

	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);
	$proporcion = $old_x/$old_y;
	$proporcion_correcta = $new_w/$new_h;
	if ($proporcion >= $proporcion_correcta) {
		$recorte_h=$old_y;
		$recorte_w=$old_y*$proporcion_correcta;
	}else{
		// si es vertical
		$recorte_h=$old_y;
		$recorte_w=$old_y*$proporcion_correcta;
		//$recorte_w=$old_x;
		//$recorte_h=$old_x/$proporcion_correcta;
	}
	$x_recorte = $old_x/2 - $recorte_w/2;
	$y_recorte = $old_y/2 - $recorte_h/2;
	$dst_img=ImageCreateTrueColor($new_w,$new_h);
	imagecopyresampled($dst_img,$src_img,0,0,$x_recorte,$y_recorte,$new_w,$new_h,$recorte_w,$recorte_h); 
	imagejpeg($dst_img,$carpeta.$filename,85);
	imagedestroy($dst_img);
	imagedestroy($src_img);
}


	crear_miniatura($_FILES['Filedata']['tmp_name'],$nuevo_nom,400,300,"../media/");
	crear_miniatura($_FILES['Filedata']['tmp_name'],"pq_".$nuevo_nom,40,40,"../media/");

source

Dummy Image Random

<img src="<a href="http://dummyimage.com/620x300/<?php" >http://dummyimage.com/620x300/<?php</a> echo dechex(rand(111,999)); ?>/fff" />

source

Alt image loaded script

// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images

// mit license. paul irish. 2010.
// webkit fix from Oren Solomianik. thx!

// callback function is passed the last image to load
//   as an argument, and the collection as `this`


$.fn.imagesLoaded = function(callback){
  var elems = this.filter('img'),
      len   = elems.length;
      
  elems.bind('load',function(){
      if (--len <= 0){ callback.call(elems,this); }
  }).each(function(){
     // cached images don't fire load sometimes, so we reset src.
     if (this.complete || this.complete === undefined){
        var src = this.src;
        // webkit hack from <a href="http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f" >http://groups.google.com/group/jquery-dev/browse_thread/thread/eee6ab7b2da50e1f</a>
        // data uri bypasses webkit log warning (thx doug jones)
        this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
        this.src = src;
     }  
  }); 

  return this;
};

source

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