@bintoro
please go through the faq in the second post.
Your site isn't loading for me - i'm getting a 500 internal server error when trying.
@wombycat
Then you do not need the resizing part. Just manually upload the slider-images you want to show in your slider-img-filepath-folder and change the following code (untested):
Code:
//rebuild image to the height and width we want in the slider
//called sprite since i got the code from our sprite addon :P
$sprite = imagecreatetruecolor($maxwidth, $maxheight);
if(is_resource($sprite) AND $article['previewimage'] )
{
$imageinfo = getimagesize($article['previewimage']);
if(is_array($imageinfo))
{
$image = null;
switch($imageinfo[2])
{
case IMAGETYPE_PNG:
$image = imagecreatefrompng($article['previewimage']);
break;
case IMAGETYPE_GIF:
$image = imagecreatefromgif($article['previewimage']);
break;
case IMAGETYPE_JPEG:
$image = imagecreatefromjpeg($article['previewimage']);
break;
default:
echo '<span style="color:red">Error occurred:</span> Unknown image format. ' . $article['previewimage']. '<br />';
break;
}
if(!is_resource($image))
{
//resiziing did not work - we are using the fallback image.
$article['previewimage'] = $fallback_img;
echo '<span style="color:red">Error occurred:</span> imagecreation failed. ' . $article['previewimage']. '<br />';
}
else
{
$img_width = $imageinfo[0];
$img_height = $imageinfo[1];
imagecopyresampled($sprite, $image, 0, 0, 0, 0, $maxwidth, $maxheight, $img_width, $img_height );
imagedestroy($image);
$img_filepath = $slider_img_filepath . 'slide_' . $i . '.jpg';
$success = imagejpeg($sprite, DIR . ($img_filepath[0] != DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : '') . $img_filepath);
imagedestroy($sprite);
if($success)
{
$article['previewimage'] = $img_filepath;
}
else
{
$img_filepath = DIR . ($img_filepath[0] != DIRECTORY_SEPARATOR ? DIRECTORY_SEPARATOR : '') . $img_filepath;
echo '<span style="color:red">Error occurred:</span> imagejpeg failed. ' . $article['previewimage']. '<br />
directory: '. $img_filepath ;
$article['previewimage'] = $fallback_img;
}
}
}
else
{
//resiziing did not work - we are using the fallback image.
$article['previewimage'] = $fallback_img;
echo '<span style="color:red">Error occurred:</span> picture is not readable.' . $article['previewimage']. '<br /> ';
}
}
else
{
//resiziing did not work - we are using the fallback image.
$article['previewimage'] = $fallback_img;
echo '<span style="color:red">Warning:</span> article has no previewimage or sprite is no ressource. ' . $article['previewimage']. '<br />';
}
to
Code:
$filename = $slider_img_filepath . 'slide_' . $article['nodeid'] . '.jpg';
if (file_exists($filename))
{$article['previewimage'] = $filename;}
else
{$article['previewimage'] = $fallback_img;}
What it does:
It does look for a file named slide_342.jpg in your slider folder. Where 342 is your articleID. If that file does exist it is used as the sliderimage. If not the fallback image is used.
If you want to use a different folder manipulate the $filename variable to your needs.
Cheers Mooff