/** * Scale an image * * LONG * * @access public * @param int The ID of an image * @param int The target width * @param int The target height * @return true */ function serendipity_scaleImg($id, $width, $height) { global $serendipity; $file = serendipity_fetchImageFromDatabase($id); if (!is_array($file)) { return false; } $admin = ''; if (!serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) { return; } $infile = $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . (empty($file['extension']) ? '' : '.' . $file['extension']); if ($serendipity['magick'] !== true) { serendipity_resize_image_gd($infile, $outfile, $width, $height); } else { $cmd = escapeshellcmd($serendipity['convert']) . ' -scale ' . serendipity_escapeshellarg($width . 'x' . $height) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile); exec($cmd, $output, $result); if ($result != 0) { echo '<span class="msg_error"><span class="icon-attention-circled"></span> ' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) . '</span>'; } unset($output, $result); } serendipity_updateImageInDatabase(array('dimensions_width' => $width, 'dimensions_height' => $height, 'size' => @filesize($outfile)), $id); return true; }
/** * Scale an image * * LONG * * @access public * @param int The ID of an image * @param int The target width * @param int The target height * @return true */ function serendipity_scaleImg($id, $width, $height) { global $serendipity; $file = serendipity_fetchImageFromDatabase($id); if (!is_array($file)) { return false; } $admin = ''; if (!serendipity_checkPermission('adminImagesMaintainOthers') && $file['authorid'] != '0' && $file['authorid'] != $serendipity['authorid']) { return; } $infile = $outfile = $serendipity['serendipityPath'] . $serendipity['uploadPath'] . $file['path'] . $file['name'] . '.' . $file['extension']; if ($serendipity['magick'] !== true) { serendipity_resize_image_gd($infile, $outfile, $width, $height); } else { $cmd = escapeshellcmd($serendipity['convert']) . ' -scale ' . serendipity_escapeshellarg($width . 'x' . $height) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile); exec($cmd, $output, $result); if ($result != 0) { echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) . '</div>'; } unset($output, $result); } serendipity_updateImageInDatabase(array('dimensions_width' => $width, 'dimensions_height' => $height, 'size' => @filesize($outfile)), $id); return true; }
function g2image_scale($album, $photo, $extension, $method = 'thumb') { global $serendipity; $gallery_base = $this->get_config('gallery_base'); $album_base = $this->get_config('album_base') . "/albums"; $album_abs = $this->get_config('album_abs'); $photo_ext = $extension ? "{$extension}" : "jpg"; $infile = $album_abs . '/albums/' . $album . '/' . $photo . '.' . $photo_ext; if ($method == 'thumb') { $outfile = $album_abs . '/tmp/' . $photo . '.thumb.' . $photo_ext; $size = $this->get_config('thumb_max'); } else { $outfile = $album_abs . '/tmp/' . $photo . '.sized.' . $photo_ext; $size = $this->get_config('popup_max'); } $fdim = @serendipity_getimagesize($infile, '', $extension); if (isset($fdim['noimage'])) { $r = array(0, 0); } else { if ($serendipity['magick'] !== true) { $r = serendipity_resize_image_gd($infile, $outfile, $size); } else { $r = array($size, $size); $newSize = $size . 'x' . $size; if ($fdim['mime'] == 'application/pdf') { $cmd = escapeshellcmd($serendipity['convert']) . ' -antialias -flatten -scale ' . serendipity_escapeshellarg($newSize) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile . '.png'); } else { $cmd = escapeshellcmd($serendipity['convert']) . ' -antialias -scale ' . serendipity_escapeshellarg($newSize) . ' ' . serendipity_escapeshellarg($infile) . ' ' . serendipity_escapeshellarg($outfile); } exec($cmd, $output, $result); if ($result != 0) { echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . sprintf(IMAGICK_EXEC_ERROR, $cmd, $output[0], $result) . '</div>'; $r = false; // return failure } else { touch($outfile); } unset($output, $result); } } }