Wednesday, August 25, 2010
Creating web thumbnails with PHP Imagick
// the location of your image $imagePath = '/path/to/source_image'; // these are treated as maximums and aspect ratio is maintained $thumbnailWidth = 100; $thumbnailHeight = 100; // path to the sRGB ICC profile $srgbPath = '/path/to/sRGB_v4_ICC_preference.icc'; // load the original image $image = new Imagick($imagePath); // get the original dimensions $width = $image->getImageWidth(); $height = $image->getImageHeight(); // set colour profile // this step is necessary even though the profiles are stripped out in the next step to reduce file size $srgb = file_get_contents($srgbPath); $image->profileImage('icc', $srgb); // strip colour profiles $image->stripImage(); // set colorspace $image->setImageColorspace(Imagick::COLORSPACE_SRGB); // determine which dimension to fit to $fitWidth = ($thumbnailWidth / $width) < ($thumbnailHeight / $height); // create thumbnail $image->thumbnailImage( $fitWidth ? $thumbnailWidth : 0, $fitWidth ? 0 : $thumbnailHeight ); // generate a thumbnail filename $imagePathParts = pathinfo($imagePath); $thumbnailPath = $imagePathParts['dirname'].'/'. $imagePathParts['filename'].'_'. $thumbnailWidth.'x'.$thumbnailHeight. '.jpg'; // save thumbnail and free up memory $image->writeImage($thumbnailPath); $image->clear(); $image->destroy();
Symfony 1.2 Embede multi forms chield tables
http://ezzatron.com/2009/12/03/expanding-forms-with-symfony-1-2-and-doctrine/
Tuesday, August 24, 2010
Bash Script to Batch Resize all Images in a Folder
A simple script which will recognize all image types in the PWD and reduce them by 50% and copy them to the resized
folder under PWD. Good for bulk resizing of images.
#!/bin/bash
files=($(file -i * | awk -F ':' 'BEGIN {ORS=""} /^.*:[ \t]*image\/[a-z]*; charset=binary/ {for(i=1;i<NF-1;i++) {print $i":"} {print $(NF-1)"\n"} }' | sed 's/ /:spacecharacter:/g' | tr '\n' ' '))
echo ${files[@]}
mkdir -p resized
for file in ${files[@]}
do
file=$(echo $file | sed 's/:spacecharacter:/ /')
convert -resize 50% "$file" resized/"$file"
#You can use mogrify instead of resize if you want to edit the images in place.
#mogrify -resize 50% "$file"
done
Copy the script to ~/bin
directory and make it executable chmod +x resize_images
. Change into the directory containing the images and execute the script.
Find Duplicate Lines in a File
sort PATH_TO_FILE | uniq -d
Continuously watch for duplicate lines as you work on a file
watch "sort PATH_TO_FILE | uniq -d"
Find Duplicate Lines in a File
sort PATH_TO_FILE | uniq -d
Continuously watch for duplicate lines as you work on a file
watch "sort PATH_TO_FILE | uniq -d"
Subscribe to:
Posts (Atom)