Skip to Content Skip to Menu

developing simple plugin, little help required.

  • radio
  • radio
  • OFFLINE
  • Posts: 18
  • Thanks: 0
  • Karma: 6
16 years 7 months ago #57654 by radio
okey Iv managed to get a version working where I resample the image and store it as a smaller thumbnail.

It works fine when logged in as admin and adding knew pics to the gallery but when i log in as a normal user and try to submit a knew image to the cb gallery it causes a fatal exception and Apache crashes and needs to restart. Any idea why this might be happening?

Here is the code:

[code:1]function getDisplayTab($tab,$user,$ui) {
global $database, $my;

$return = null;
$params = $this->params; // get parameters (plugin and related tab)


$count = intval($params->get( 'count', 3) );
$widththumbcb = intval( $params->get( 'width_thumbcb', 60) );
$heightthumbcb = intval( $params->get( 'height_thumbcb', 80) );

if($tab->description != null) {
$return .= "\t\t<div class=\"tab_Description\">"
. $tab->description // html content is allowed in descriptions
. "</div>\n";
}

// knew function for resampling the images

function createthumb($image,$filename,$new_w,$new_h){
$system=explode('.',$image);
if (preg_match('/jpg|jpeg/',$system[1])){
$src_img=imagecreatefromjpeg($image);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($image);
}
$image_width = imagesx($src_img);
$image_height = imagesy($src_img);

if ($image_width <= $new_w) {
$needs_new_width = false;
$resize_width_factor = 1;
} else {
$needs_new_width = true;
$resize_width_factor = $new_w / $image_width;
}
if ($image_height <= $new_h) {
$needs_new_height = false;
$resize_height_factor = 1;
} else {
$needs_new_height = true;
$resize_height_factor = $new_h / $image_height;
}


$resize_factor = min($resize_width_factor,$resize_height_factor);
$new_height = floor($image_height * $resize_factor);
$new_width = floor($image_width * $resize_factor);

$dst_img=imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);


if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}


$query = "SELECT*"
."\n FROM jos_comprofiler_plug_profilegallery"
."\n WHERE userid=".$user->id
. "\n ORDER BY pgitemdate DESC"
. "\n LIMIT ".$count;



$database->setQuery($query);
$rows=$database->loadObjectList();

foreach($rows as $row) {

$PGItemPath= "images/comprofiler/plug_profilegallery/";
$pgitemfilename = $row->pgitemfilename;
$PGItemUserPath = $PGItemPath . $user->id . "/".$pgitemfilename;



if ( $row->pgitempublished != 1 || $row->pgitemapproved != 1 ) {

$return =' ';
}

else

$image = createthumb($PGItemUserPath,"images/comprofiler/plug_profilegallery/".$user->id."/tn_".$pgitemfilename, $widththumbcb, $heightthumbcb);

$PGItemUserPath2 = $PGItemPath.$user->id.'/tn_'.$pgitemfilename;


$img = "<img src=\"".$PGItemUserPath2."\" alt=\" "." \" border=\"0\"/>";

$link_cb = $PGItemPath . $user->id . "/".$pgitemfilename;

$return .= "\t\t<div class=\"connectionBox\" >\n"
. '<p><a title="" target="_blank" href="'.$link_cb.'">'.$img.'</a></p>'
. "</div>\n";


}
return $return;
} // end or getDisplayTab function
} // end of gethelloworldTab class
[/code:1]

Post edited by: radio, at: 2008/02/27 03:39

Post edited by: radio, at: 2008/02/27 03:41

Interested in improving Joomla as a social networking platform? If yes join joomlaplazza.com

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
16 years 7 months ago #57674 by nant
turn on your debug settings and also check your website logs for hints.

Please Log in or Create an account to join the conversation.

  • radio
  • radio
  • OFFLINE
  • Posts: 18
  • Thanks: 0
  • Karma: 6
16 years 7 months ago #57689 by radio
Could this whole section be replaced with the imagetoolbox class to achieve the same outcome?

[code:1]function createthumb($image,$filename,$new_w,$new_h){
$system=explode('.',$image);
if (preg_match('/jpg|jpeg/',$system[1])){
$src_img=imagecreatefromjpeg($image);
}
if (preg_match('/png/',$system[1])){
$src_img=imagecreatefrompng($image);
}
$image_width = imagesx($src_img);
$image_height = imagesy($src_img);

if ($image_width <= $new_w) {
$needs_new_width = false;
$resize_width_factor = 1;
} else {
$needs_new_width = true;
$resize_width_factor = $new_w / $image_width;
}
if ($image_height <= $new_h) {
$needs_new_height = false;
$resize_height_factor = 1;
} else {
$needs_new_height = true;
$resize_height_factor = $new_h / $image_height;
}


$resize_factor = min($resize_width_factor,$resize_height_factor);
$new_height = floor($image_height * $resize_factor);
$new_width = floor($image_width * $resize_factor);

$dst_img=imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);


if (preg_match("/png/",$system[1]))
{
imagepng($dst_img,$filename);
} else {
imagejpeg($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
} [/code:1]

Post edited by: radio, at: 2008/02/27 14:27

Interested in improving Joomla as a social networking platform? If yes join joomlaplazza.com

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum