Use imagick in code instead of GD

Hi everyone,

I will try to make this short. I need to alter the code function below to use imagicks resize function instead.

Can you add imagick so it uses that if installed or completly change to use imagemagick instead (i have that installed)

[php]public function create_download_size( $size, $location=null ){

      $image_p = imagecreatetruecolor( $size['width'], $size['height'] );
      $image = imagecreatefromjpeg( $location );

      list( $current_image['width'], $current_image['height'] ) = getimagesize( $location );
      imagecopyresampled($image_p, $image, 0, 0, 0, 0, $size['width'], $size['height'], $current_image['width'], $current_image['height']);

      $destination_file = $this->tmp_dir . basename( $location );

     if ( ! file_exists( $destination_file ) ){
         wp_mkdir_p( dirname( $destination_file ) );
     }

[/php]

The code above does the job of creating a different size of my original photo at the time of purchase - but as an photographer it also takes away all information on the photo. This renders a photo useless since all colorprofile, copyright, resolution is gone.

From what I have been told - imagick does this differently and saves the exif information. So I need this function to use imagick:resize instead of imagecopyresampled.

A note: the function must preserve original file.

To explain the workflow. I upload my original image to the site - a newspaper or magazine sees the image and want a medium sized image - they buy that and tells the shopping cart to create a medium sized photo from the original and makes it ready for download.

Can anyone help me? I hope you understand - english is not my spoken langugage.

//mxfarsa

You probably won’t be able to use exec(); if you’re on a shared host so you could use the imagick class:

[php]$im = new imagick($input_path);
$im->setImageResolution(2550,3300);
$im->setImageFormat(‘jpeg’);
$im->setImageCompression(imagick::COMPRESSION_JPEG);
$im->setImageCompressionQuality(100);
$im->writeImage($output_path);
$im->clear();
$im->destroy();
[/php]

I don’t think this removes the EXIF data as to do this you would use a separate command -strip which strips out the EXIF data.

Ok, i´ll give it a try,

Thank you for the answer :slight_smile:

Regards,

Henrik

Sponsor our Newsletter | Privacy Policy | Terms of Service