<?php
function imageResize($width, $height, $target) {
//takes the larger size of the width and height and applies the
formula accordingly...this is so this script will work
dynamically with any size image
if ($width > $height) {
$percentage = ($target / $width);
} else {
$percentage = ($target / $height);
}
//gets the new value and applies the percentage, then rounds the value
$width = round($width * $percentage);
$height = round($height * $percentage);
//returns the new sizes in html image tag format...this is so you
can plug this function inside an image tag and just get the
return "width="$width" height="$height"";
}
?>
//Then in the HTML:
<?php
//get the image size of the picture and load it into an array
$mysock = getimagesize("images/sock001.jpg");
?>
<!-using a standard html image tag, where you would have the
width and height, insert your new imageResize() function with
the correct attributes -->
<img src="images/sock001.jpg" <?php imageResize($mysock[0],
$mysock[1], 150); ?>>
Tag Archive for resize
image resize dynamically
Resize NSSplitView Nicely
- (void) splitView:(NSSplitView *)sender resizeSubviewsWithOldSize:(NSSize)oldSize {
// <a href="http://www.wodeveloper.com/omniLists/macosx-dev/2003/May/msg00261.html" >http://www.wodeveloper.com/omniLists/macosx-dev/2003/May/msg00261.html</a>
// grab the splitviews
NSView *left = [[sender subviews] objectAtIndex:0];
NSView *right = [[sender subviews] objectAtIndex:1];
float dividerThickness = [sender dividerThickness];
// get the different frames
NSRect newFrame = [sender frame];
NSRect leftFrame = [left frame];
NSRect rightFrame = [right frame];
// change in width for this redraw
int dWidth = newFrame.size.width - oldSize.width;
// ratio of the left frame width to the right used for resize speed when both panes are being resized
float rLeftRight = (leftFrame.size.width - MIN_LEFT_PANEL_W) / rightFrame.size.width;
// resize the height of the left
leftFrame.size.height = newFrame.size.height;
leftFrame.origin = NSMakePoint(0,0);
// resize the left & right pane equally if we are shrinking the frame
// resize the right pane only if we are increasing the frame
// when resizing lock at minimum width for the left panel
if(leftFrame.size.width <= MIN_LEFT_PANEL_W && dWidth < 0) {
rightFrame.size.width += dWidth;
} else if(dWidth > 0) {
rightFrame.size.width += dWidth;
} else {
leftFrame.size.width += dWidth * rLeftRight;
rightFrame.size.width += dWidth * (1 - rLeftRight);
}
rightFrame.size.width = newFrame.size.width - leftFrame.size.width - dividerThickness;
rightFrame.size.height = newFrame.size.height;
rightFrame.origin.x = leftFrame.size.width + dividerThickness;
[left setFrame:leftFrame];
[right setFrame:rightFrame];
}
PyS60 – Thread
import appuifw
import e32
import graphics
import thread
import time
class Main:
def __init__(self):
appuifw.app.title = u'Fibonacci'
appuifw.app.body = self.canvas = appuifw.Canvas()
appuifw.exit_key_handler = self.OnExit
appuifw.app.menu = [(u'Calcola', self.OnCalcola)]
self.nlock = thread.allocate_lock() # Allocazione di un lock per il thread
self.vlock = thread.allocate_lock()
self.ris1 = 0
self.ris2 = ''
self.loop = 1
self.indice = 0
self.img = graphics.Image.new(self.canvas.size)
self.OnLoop()
def OnCalcola(self):
numero = appuifw.query(u'Inserire un Numero', 'number')
thread.start_new_thread(self.fibonacci, (numero, ))
def fibonacci(self, n):
self.ris1 = time.strftime('%H:%M:%S')
self.ris2 = ''
a, b = 0, 1
for i in range(n):
a, b = b, a + b
self.nlock.acquire()
self.indice = ((i+1)*100)/n
self.nlock.release()
self.nlock.acquire()
self.ris2 = time.strftime('%H:%M:%S')
self.nlock.release()
def OnExit(self):
self.loop = 0
def OnLoop(self):
while self.loop:
e32.ao_sleep(0.1)
self.img.clear(0)
self.img.line([37, 50, 137, 50], 0xffffff, width=20)
self.img.line([37, 50, 37 + self.indice, 50], 0xfffc0d, width=20)
self.img.text((80, 55), u'' + str(self.indice) + u'%', 0x000000)
self.vlock.acquire()
if self.ris2 <> '':
self.img.text((45, 80), u'Start: ' + str(self.ris1), 0xffffff)
self.img.text((45, 92), u'End: ' + str(self.ris2), 0xffffff)
self.canvas.blit(self.img)
self.vlock.release()
if __name__ == '__main__':
main = Main()
Python – create attributes
class Demo: pass # Oggetto contenitore def createAttributes(): rc = Demo() setattr(rc, 'myobj', 'valore') return rc
Python – scrittura in unicode
import codecs
fp = codecs.open('E:demo.txt', 'w', 'utf_8')
fp.write('cioè')
fp.close()
Object paternity
// relationship of object 1 to object 2
function objectPaternity(obj1, obj2) {
// given an object this function returns 'child' if obj1 is a child of obj2
// and 'parent' if obj1 is a parent of obj2 - then 'no' if neither
var relationship = 'no';
var currentElement = obj1;
while((typeof currentElement.parentNode != 'undefined') && (currentElement != document.body)) {
// first cycle through all the parent elements of object 1 to see if object 2 is one of them
if(currentElement.parentNode == obj2) {
relationship = 'child';
}
// walk up the tree and try again
currentElement = currentElement.parentNode;
}
// if object 1 is not a child of object 2 then we test the other way arround
if(relationship == 'no') {
currentElement = obj2;
while((typeof currentElement.parentNode != 'undefined') && (currentElement != document.body)) {
// now cycle through all the parent elements of object 2 to see if object 1 is one of them
if(currentElement.parentNode == obj1) {
relationship = 'parent';
}
// walk up the tree and try again
currentElement = currentElement.parentNode;
}
}
return relationship;
}
Category: Uncategorized |
Tags: css, dhtml, DOM, dragdrop, Firefox, greasemonkey, image, javascript, object, onload, paternity, resize, unobtrusive
fast through a list
var i = list.length;
for(i; i> 0; i--) {
alert(i)
}
Category: Uncategorized |
Tags: css, dhtml, DOM, dragdrop, Firefox, greasemonkey, image, itteration, javascript, onload, resize, unobtrusive
Resize window
<script type="text/javascript"> self.resizeTo(100,200); </script>
Resize Image
function resize_image($filename, $tmpname, $xmax, $ymax)
{
$ext = explode(".", $filename);
$ext = $ext[count($ext)-1];
if($ext == "jpg" || $ext == "jpeg")
$im = imagecreatefromjpeg($tmpname);
elseif($ext == "png")
$im = imagecreatefrompng($tmpname);
elseif($ext == "gif")
$im = imagecreatefromgif($tmpname);
$x = imagesx($im);
$y = imagesy($im);
if($x <= $xmax && $y <= $ymax)
return $im;
if($x >= $y) {
$newx = $xmax;
$newy = $newx * $y / $x;
}
else {
$newy = $ymax;
$newx = $x / $y * $newy;
}
$im2 = imagecreatetruecolor($newx, $newy);
imagecopyresized($im2, $im, 0, 0, 0, 0, floor($newx), floor($newy), $x, $y);
return $im2;
}