0

i wrote following code to generate thumbnails for images in php,it was working fine for some images but In case of high resolution/high size images it was showing

This page isn’t working

issue. Here imagecreatefromjpeg() is not working. What is the solution for this Please help me..

function make_accused_thumb($src, $dest, $desired_width) {

/* read the source image */
//ini_set('gd.jpeg_ignore_warning', 1);
//echo $src;exit;
//echo $src;exit;
$source_image = @imagecreatefromjpeg($src);
echo $src;exit;
if (!$source_image)
{
  $source_image= @imagecreatefromstring(file_get_contents($src));
}

$width = @imagesx($source_image);
$height = @imagesy($source_image);

/* find the "desired height" of this thumbnail, relative to the desired width  */
$desired_height = @floor($height * ($desired_width / $width));

/* create a new, "virtual" image */
$virtual_image = @imagecreatetruecolor($desired_width, $desired_height);

/* copy source image at a resized size */
@imageCopyResized($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);

/* create the physical thumbnail image to its destination */
@header('Content-Type: image/jpeg');
@imagejpeg($virtual_image, $dest);

}
brombeer
  • 8,716
  • 5
  • 21
  • 27

1 Answers1

0

If you’ve ever done any sort of image processing in your PHP applications, you’ll start to realise how limited you are when using native PHP commands such as createimagefromjpg etc. It eats your web servers memory! Nowadays, what with people carrying 10 Megapixel cameras in their phones, uploading and resizing a photo can be a real strain on resources, especially if several users on the website are doing it at the same time.

To get around this conundrum, there is a PHP library called imagick (a wrapper class) which allows you to access a terminal program called ImageMagick. ImageMagick runs natively on the machine, and is available for Unix, Linux, Mac, and Windows, so running it shouldn’t be a problem. The only thing to take into consideration here is whether your hosting providers PHP has imagick available. If not, depending on your hosting package you may be able to SSH into your server and install it.

As soon as I switched to using the IMagick PHP class, the errors stopped, and the site sped up considerably.

Here's how to install on Linux and Windows:

Howto: Install Imagick (for php) on Ubuntu 11.10

How to install ImageMagick to use with PHP on Windows 7 (3)

Here's the docs for the IMagick class: http://be2.php.net/manual/en/class.imagick.php

delboy1978uk
  • 12,118
  • 2
  • 21
  • 39