LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#26 January 29 2010

richy
Member

Re: How to Resize a set of pictures

Thank you.

arithma wrote:
xterm wrote:
richy wrote:

I don't believe how I wasted so much time resizing every picture on its own.

Welcome to lebgeeks.

I wasted 10 hours figuring out how to resize images I could have done in 2 hours.. - well most of the time was setting up ImageMagick which is hell, but still: welcome to lebgeeks !

Offline

#27 January 29 2010

nablaux
Member

Re: How to Resize a set of pictures

rahmu wrote:
nablaux wrote:

Well I guess the easiest way is to write a for loop in c++ that reads all the images and then resize them. To do that, use a library called CImg.h it is just a header file that you include and that is it.
After that, read all images in the folder and put them in an imageList and then loop the imageList and invoke the function resize on each image then save it.

If you choose to take that path and found problems let me know I can post some code :)

I would still use a bash script over a C++ code. But still I'm interested. Where do I get CImg.h? Is it a standard library?

You can download it from http://cimg.sourceforge.net/ , it is a very useful library but of course it is not as fancy as ImageMagick.
I use it for all my image processing tasks and vector/matrix manipulations. It is straight forward and doesnt have fancy names for things like opencv for example.
The best thing about it is that it is all in a header file and templated so you can have images of int or floats or doubles etc... and there is nothing to setup. It also handles displaying images on the screen.
The only annoying thing about it is that since it is a header file it needs to be compiled everytime and since it is a big file the compilation of the program will be slow especially if you add some optimization flags.
Anyway, I am happy with it :) and I do recommend it

Offline

#28 February 4 2010

pikatore
Member

Re: How to Resize a set of pictures

guys guys guys!!!!

USE PICASA! I have to batch resize pictures all the time, and Picasa kicks ass (it also has a ton of other features as well, I highly recommend it)

Offline

#29 March 2 2010

Kassem
Member

Re: How to Resize a set of pictures

proners wrote:

so i've made a quick and dirty jab at resizing using wamp, this is just for one image, a few adjustments are needed to automate the process for multiple images

first page: html form

<head><title>form_to_supply_images_to_script</title></head>

<body>
	<form name="images_form" action="handle_images.php" method=POST enctype="multipart/form-data">
	<fieldset>
	
	<input type=file name=limage /> <br />;

	</fieldset>
	<input type="submit" value="Process" />
	</form>
</body>

</html>

now handle_images.php code:

<?php
$img = $_FILES['limage'];
//image attributes made simpler
$img_name = $img['name'];
$img_size = $img['size'];
$img_type = $img['type'];
$img_tmp = $img['tmp_name'];

$img_ext = substr(strrchr( $img_name, "."), 1); // get extension
$img_ext = strtolower($img_ext); // to avoid some bugs

// here i am supposing that we're only working with jpg images, if not, it destroys the file and stops the script
if(($img_ext != "jpg") && ($img_ext != "jpeg"))
{
unlink($img_tmp);
die("file supplied is not an image");
}


list($width, $height) = getimagesize($img_tmp); //get image with and height

$src = imagecreatefromjpeg($img_tmp); // create a source image to use, raw image!


$new_width = 100; //resized image width, change this value to the one required
$new_height = ($height/$width)*$new_width; // to keep the aspect ratio

$tmp = imagecreatetruecolor($new_width,$new_height); //temporary image where resized image will be put


imagecopyresampled($tmp,$src,0,0,0,0,$new_width,$new_height,$width,$height); // the main trick 


imagejpeg($tmp,$img_name,100); // create jpeg image from raw $tmp with the name $image_name with 100 percent quality, reduce quality to reduce size

This script is actually very interesting. I have a similar one that does a little more than this, basically it checks whether the height or the width is larger and then resizes accordingly... but I kinda feel like I messed up the ratios lol. But anyway, the GD library can certainly do great things, it's definitely worth looking at :)

Offline

#30 April 6 2010

aarenlainey
Banned

Re: How to Resize a set of pictures

1)Open the photo file in Photoshop. Most digital camera file are created at 72 dpi. If you are creating a web document you will not need to adjust the dpi. If your output is for a printer whether commercial or your personal inkjet you must change the dpi for a good quality print.
2)Pull down the “Image Menu” bar and select the “Image Size” menu. There is a box to adjust the dpi. Change the size from 72 to 300. Make sure the “Resample Image” check box is unchecked, but the “Constrain Proportions” check box is checked.
3)Pull down the “Image Menu” bar and select the “Image Size” menu. There is a box to resize the photo. Make sure the “Resample Image” and the “Constrain Proportions” check box is checked. You may change the size of the photo by entering either the desired pixel size, for the web, or the desired document size for print. Chose either the height or the width.
4)If the proportions are not correct turn your ruler on using the “View” menu, select ruler. Pull the guidelines down to measure off where you want to crop the drawing. For example, if after you resize the drawing it is 3 inches by 2 ½ inches and you need the final photo to be 3 inches by 2 inches, drag the guide line to the 2 inch mark and use the crop tool to resize the proportion.

Offline

#31 April 6 2010

rolf
Member

Re: How to Resize a set of pictures

I still recommend batch processing through photoshop, but here is a php function for resizing if anyone is interested. It takes and return strings, so it needs to be used in conjunction with file functions (fopen, etc..) and directory parsing if you want it to process multiple files.

function resize($imagedata, $thumbsize=90, $size_axis=false)
	{
	// resizes image so that $size_axis == $thumbsize . If $size_axis is not properly set then it will pick the biggest of x,y
	// possible values for $size_axis : 'x', 'y' (anything else is equivalent to "autodetection")
	// $imagedata is a string containing the image binary data (can be of any type supported by gd2: jpeg, gif, etc..)
	// function returns a string containing the binary data of the thumbnail compressed as JPEG, or false if something goes wrong.

	extension_loaded('gd') or dl("php_gd2");

	// load image
	$image = imagecreatefromstring($imagedata);
	$imagewidth = imagesx($image); 
	$imageheight = imagesy($image);

	// choose x or y axis
	if ($size_axis!='x' and $size_axis!='y') {
		// automatic detection of the biggest axis
		if ( $imagewidth > $imageheight) {
			$size_axis = 'x';
		} else {
			$size_axis = 'y';
		}
	}

	// calculate resize ratio
	if ($size_axis == 'x') { 
	  // x is set
	  $thumbwidth = $thumbsize; 
	  $factor = $thumbsize / $imagewidth; 
	  $thumbheight = (int) ($imageheight * $factor); 
	} else {
	  // y is set 
	  $thumbheight = $thumbsize;
	  $factor = $thumbsize / $imageheight;
	  $thumbwidth = (int) ($imagewidth * $factor);
	}

	// generate thumbnail
	$thumb = imagecreatetruecolor($thumbwidth,$thumbheight);
	imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);		


	// compress and return (imagejpeg() outputs to the browser, so we need to catch the output with ob_)
	ob_start();
	if( imagejpeg($thumb) ) {
		$thumbdata = ob_get_contents();
		ob_end_clean();
		imagedestroy($image);
		imagedestroy($thumb);
		return $thumbdata;
	} else {
		ob_end_clean();
		return false;	
	}
}

Last edited by rolf (April 6 2010)

Offline

#32 April 6 2010

Xsever
Member

Re: How to Resize a set of pictures

I found a software called Format Factory. It converts all sorts of formats to all sorts of formats (audio, video, pictures, ....)

It's a very handy and easy to use piece of software.

Open-Source FTW !

Offline

#33 April 6 2010

J4D
Member

Re: How to Resize a set of pictures

format factory is gold !  have been using it for years now , converts anything to everything !

Offline

Board footer