Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS 

Howto resize multiple pictures, graphics, images

for k in $(ls *.jpg); do convert -resize 800 -quality 80 $k r800-$k; done

Batch re-size a collection of images from the command line

for img in $(ls *.png); do convert $img -resize 75% smaller-$img; done;

C#: Resize An Image While Maintaining Aspect Ratio and Maximum Height

// This allows us to resize the image. It prevents skewed images and
// also vertically long images caused by trying to maintain the aspect
// ratio on images who's height is larger than their width

public void ResizeImage(string OriginalFile, string NewFile, int NewWidth, int MaxHeight, bool OnlyResizeIfWider)
{
	System.Drawing.Image FullsizeImage = System.Drawing.Image.FromFile(OriginalFile);

	// Prevent using images internal thumbnail
	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);
	FullsizeImage.RotateFlip(System.Drawing.RotateFlipType.Rotate180FlipNone);

	if (OnlyResizeIfWider)
	{
		if (FullsizeImage.Width <= NewWidth)
		{
			NewWidth = FullsizeImage.Width;
		}
	}

	int NewHeight = FullsizeImage.Height * NewWidth / FullsizeImage.Width;
	if (NewHeight > MaxHeight)
	{
		// Resize with height instead
		NewWidth = FullsizeImage.Width * MaxHeight / FullsizeImage.Height;
		NewHeight = MaxHeight;
	}

	System.Drawing.Image NewImage = FullsizeImage.GetThumbnailImage(NewWidth, NewHeight, null, IntPtr.Zero);

	// Clear handle to original file so that we can overwrite it if necessary
	FullsizeImage.Dispose();

	// Save resized picture
	NewImage.Save(NewFile);
}

Image/canvas bliting

I can't remember how to call the blit method.
So, here's just a personal reminder.
(BTW, the pys60 doc has a wrong order between target and source)
app.body = c = Canvas()
w,h = 20,20
im = Image.new(size=(w,h))

# here's prototype
# blit(im, source=(0,0,w,h), target=(0,0), mask=None, scale=0)
# here are examples
c.blit(im)  # put entire image on top-left
c.blit(im, target=(70,70)) # put it about mid-screen
c.blit(im, (0,0,w/2,h/2))  # put a quater image on top-left

# double the image size and put it about mid-screen
c.blit(im, target=(60,60,100,100), scale=1)

If scale is not specified and source <> target, the image
will be clipped instead of resized.

mask is a 1-bit image with the same size as image.
mask = Image.new((w,h),'1')

Pixel on the image will be copied if the same pixel
on the mask is 'white'.
So we can use mask to make 'Sprite'.

Readable, resizable font in stylesheet

body, td {font:90% Tahoma, [other fonts]}

Today I found an apps where its Thai font is ugly.
I added this 90% Tahoma to its font style.
Don't use pixel (px). It's unresizable (unless using FF).

Drag and Drop image with javascript

<body>
<script src="http://www.walterzorn.com/scripts/wz_dragdrop.js"></script>

<img name="name1" src="someImg.jpg" width=240 height=135>

<script>SET_DHTML("name1")</script>
</body>

You can make the image resizable (using shift-drag) by
SET_DHTML("name1"+RESIZABLE) // any size
SET_DHTML("name1"+SCALABLE) // keep aspect ratio

See more detail here
http://www.walterzorn.com/dragdrop/dragdrop_e.htm
« Newer Snippets
Older Snippets »
Showing 1-6 of 6 total  RSS