May 09

mod_rewrite problems in Apache2 + Ubuntu ?

How to check whether mod_rewrite is installed?

Create a text file named check.php in the www folder and insert the following code to it.

<?php phpinfo(); ?>

Then go to the web page in your browser using the url “localhost/check.php”. Then you’ll see information about the php version of the system. Under the “Configuration” title there’s another title called “apache2handler”. In that table there’ll be a entry named “Loaded Modules”. Check to see if it contains the name “mod_rewrite “.If you can see that name then mod_rewrite is installed to apache.

If mod_rewrite is not installed?

mod_rewrite can be installed using the “sudo a2enmod rewrite” command in the terminal.

How to check whether mod_rewrite is working properly?

A good tutorial on this can be found in http://www.webune.com/forums/how-to-test-check-if-mod-rewrite-is-enabled-t40.html.

mod_rewrite is not working even though it is installed?

Navigate to /etc/apache2/sites-enabled as root and open the text file “000-default”. Then replace all the “AllowOverride None” with “AllowOverride All”( There’ll be 3 entries ). Then restart apache using sudo /etc/init.d/apache2 restart .

This should solve the problems.

Share Button
Feb 10

Can’t play songs in Amarok after installing it in ubuntu?

I installed Amarok in Ubuntu Yesterday. But the problem was it couldn’t play mp3/mpg/mp4/m4a files. After a bit of searching I was able to figure out a solution. What you have to do is to install libxine1-ffmpeg package. It just a simple

sudo apt-get install libxine1-ffmpeg

Then everything worked fine for me. Hope this helps…!

Share Button
Jan 24

Handling images in java using imageIO

Have you ever faced the need of sending an image through a network using a Java program? If yes, you must have probably read the image to a byte array sent it through the network. The problem with this method is it is too long and you have to remake the image file ( using the received byte array) at the destination to take any use of it.

But in this article I’m going to show how to read an image to a Java class called “Image” and use it appropriately. You can use this “Image” class directly in GUI’s, send it through networks, store it, etc. Sol let’s look at the code now. The code consists of two parts. Reading the image to an instance of the “Image” class and writing it back to the hard drive. I have put comments in almost every step. So understanding the code should be easy.

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.imageio.ImageReadParam;
import javax.imageio.ImageReader;
import javax.imageio.stream.ImageInputStream;

public class Main {

 public void copyImage(){

 //path of the image to be read
 String path="picture.jpg";

 //create a file entry in java for that image
 File imageSrc=new File(path);

 if(!imageSrc.exists()){
 System.out.println("Input image does not exist.");
 System.exit(0);
 }

 try {

 /*
 * This part of the code is for reading the image in to
 * an instance of an Image class.
 */

 //Create a stream to read the image
 ImageInputStream iis = ImageIO.createImageInputStream(imageSrc);
 /*
 * ImageIO is a class containing static convenience methods for locating
 *ImageReaders and ImageWriters, and performing simple encoding and decoding.
 */

 //get a collection of Image readers which support jpg
 Iterator<?> imgReaders = ImageIO.getImageReadersByFormatName("jpg");

 //get the first image reader from the collection
 ImageReader reader = (ImageReader) imgReaders.next();

 //set the input for the image reader
 reader.setInput(iis, true);
 /*
 * Setting seekForwardOnly parameter ensures that the image file is
 * read in the ascending order.
 *
 */

 //to ensure that the default read parameters are used when
 //decoding data from the stream
 ImageReadParam param = reader.getDefaultReadParam();

 //read the image
 Image image = reader.read(0, param);

 /*
 *
 * This part of the code is for writing the image object
 * back to the hard disk as an image file.
 */

 //To render the image
 BufferedImage bufferedImage = new BufferedImage(image.getWidth(null),
image.getHeight(null), BufferedImage.TYPE_INT_RGB);

 //using "painter" we can draw in to "bufferedImage"
 Graphics2D painter = bufferedImage.createGraphics();

 //draw the "image" to the "bufferedImage"
 painter.drawImage(image, null, null);

 //the new image file
 File outputImg=new File("output.jpg");

 //write the image to the file
 ImageIO.write(bufferedImage, "jpg", outputImg);

 System.out.println("Image transfer was successful...!");

 } catch (IOException ex) {
 Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
 }
 }

 public static void main(String[] args) {
 // TODO code application logic here

 Main main=new Main();
 main.copyImage();
 }

}

You can download the text file from here.

As you must have understood, I have written the code to read a JPEG image. I tested the same code for BMP, PNG, and TIFF. All those formats worked just fine. The only draw back that I saw was there is a quality loss when using JPEG. To change the image format, change the following code segments (change xxx to the desired foramt).

//path of the image to be read

String path="picture.xxx";

————————————————————————————————————————————————————————–

//get a collection of Image readers which support jpg
 Iterator<?> imgReaders = ImageIO.getImageReadersByFormatName("xxx");

————————————————————————————————————————————————————————–

//the new image file
File outputImg=new File("output.xxx");

————————————————————————————————————————————————————————–

//write the image to the file
ImageIO.write(bufferedImage, "bmp", outputImg);

————————————————————————————————————————————————————————–

If you used a byte array to read the image file, you have to make an image file( on the hard drive) before you use that image again. But using the above method you can directly use it in the Java program. Click here to see an example on that.

As you can see, the possibilities are endless. So experiment and enjoy…..!

Share Button