praegune kellaaeg 19.06.2025 21:54:39
|
Hinnavaatlus
:: Foorum
:: Uudised
:: Ärifoorumid
:: HV F1 ennustusvõistlus
:: Pangalink
:: Telekavad
:: HV toote otsing
|
|
autor |
|
h2rra
HV vaatleja
liitunud: 04.11.2008
|
25.01.2010 03:56:12
Kiire php küsimus ja wordpress |
|
|
Tervitus, saan phpst vaid väga algelisi asju aru ja seega on vaja teie abi. Ma leidsin netist php pildi unsharp mask filtri funktsiooni ja tahaks selle wordpressi thumbnail generaatorile külge pookida, kuid ise ei oska. Vaja on ainult jpeg teravustamist. Kui ma olen millestki valesti aru saanud, nt valed koodiread pastenud, siis andke julgelt teada
See peaks olema see osa, mis WPs thumbnaili genereerib
Spoiler 
function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $dest_path = null, $jpeg_quality = 100 ) {
$image = wp_load_image( $file );
if ( !is_resource( $image ) )
return new WP_Error('error_loading_image', $image);
$size = @getimagesize( $file );
if ( !$size )
return new WP_Error('invalid_image', __('Could not read image size'), $file);
list($orig_w, $orig_h, $orig_type) = $size;
$dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
if ( !$dims )
return $dims;
list($dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) = $dims;
$newimage = wp_imagecreatetruecolor( $dst_w, $dst_h );
imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
// convert from full colors to index colors, like original PNG.
if ( IMAGETYPE_PNG == $orig_type && !imageistruecolor( $image ) )
imagetruecolortopalette( $newimage, false, imagecolorstotal( $image ) );
// we don't need the original in memory anymore
imagedestroy( $image );
// $suffix will be appended to the destination filename, just before the extension
if ( !$suffix )
$suffix = "{$dst_w}x{$dst_h}";
$info = pathinfo($file);
$dir = $info['dirname'];
$ext = $info['extension'];
$name = basename($file, ".{$ext}");
if ( !is_null($dest_path) and $_dest_path = realpath($dest_path) )
$dir = $_dest_path;
$destfilename = "{$dir}/{$name}-{$suffix}.{$ext}";
if ( IMAGETYPE_GIF == $orig_type ) {
if ( !imagegif( $newimage, $destfilename ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
} elseif ( IMAGETYPE_PNG == $orig_type ) {
if ( !imagepng( $newimage, $destfilename ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
} else {
// all other formats are converted to jpg
$destfilename = "{$dir}/{$name}-{$suffix}.jpg";
if ( !imagejpeg( $newimage, $destfilename, apply_filters( 'jpeg_quality', $jpeg_quality, 'image_resize' ) ) )
return new WP_Error('resize_path_invalid', __( 'Resize path invalid' ));
}
imagedestroy( $newimage );
// Set correct file permissions
$stat = stat( dirname( $destfilename ));
$perms = $stat['mode'] & 0000666; //same permissions as parent folder, strip off the executable bits
@ chmod( $destfilename, $perms );
return $destfilename;
} |
Ja see on pildi teravustja:
Spoiler 
/*
* Unsharp Mask for PHP - version 2.1.1
* Unsharp mask algorithm by Torstein Hųnsi 2003-07.
* thoensi_at_netcom_dot_no.
* Please leave this notice.
*/
function unsharpMask($sharpenAmount,$sharpenRadius,$sharpenThreshold) {
/*
* New:
* - In version 2.1 (February 26 2007) Tom Bishop has done some important speed enhancements.
* - From version 2 (July 17 2006) the script uses the imageconvolution function in PHP
* version >= 5.1, which improves the performance considerably.
*
*
* Unsharp masking is a traditional darkroom technique that has proven very suitable for
* digital imaging. The principle of unsharp masking is to create a blurred copy of the image
* and compare it to the underlying original. The difference in colour values
* between the two images is greatest for the pixels near sharp edges. When this
* difference is subtracted from the original image, the edges will be
* accentuated.
*
* The Amount parameter simply says how much of the effect you want. 100 is 'normal'.
* Radius is the radius of the blurring circle of the mask. 'Threshold' is the least
* difference in colour values that is allowed between the original and the mask. In practice
* this means that low-contrast areas of the picture are left unrendered whereas edges
* are treated normally. This is good for pictures of e.g. skin or blue skies.
*
* Any suggenstions for improvement of the algorithm, expecially regarding the speed
* and the roundoff errors in the Gaussian blur process, are welcome.
*/
// $this->workingImage is an image that is already created within php using
// imgcreatetruecolor. No url! $this->workingImage must be a truecolor image.
// set the optimal default values for sharpening, with slight sharpening
// if (!$sharpenAmount) $sharpenAmount = 38;
// if (!$sharpenRadius) $sharpenRadius = 0.8;
// if (!$sharpenThreshold) $sharpenThreshold = 0;
// Attempt to calibrate the parameters to Photoshop
if ($sharpenAmount > 500) $sharpenAmount = 500;
$sharpenAmount = $sharpenAmount * 0.016;
if ($sharpenRadius > 50) $sharpenRadius = 50;
$sharpenRadius = $sharpenRadius * 2;
if ($sharpenThreshold > 255) $sharpenThreshold = 255;
$sharpenRadius = abs(round($sharpenRadius)); // Only integers make sense.
if ($sharpenRadius == 0) {
return $this->workingImage; imagedestroy($this->workingImage); break;
}
$w = imagesx($this->workingImage); $h = imagesy($this->workingImage);
$imgCanvas = imagecreatetruecolor($w, $h);
$imgBlur = imagecreatetruecolor($w, $h);
// Gaussian blur matrix:
//
// 1 2 1
// 2 4 2
// 1 2 1
//
//////////////////////////////////////////////////
if (function_exists('imageconvolution')) { // PHP >= 5.1
$matrix = array(
array( 1, 2, 1 ),
array( 2, 4, 2 ),
array( 1, 2, 1 )
);
imagecopy ($imgBlur, $this->workingImage, 0, 0, 0, 0, $w, $h);
imageconvolution($imgBlur, $matrix, 16, 0);
}
else {
// Move copies of the image around one pixel at the time and merge them with weight
// according to the matrix. The same matrix is simply repeated for higher radii.
for ($i = 0; $i < $sharpenRadius; $i++) {
imagecopy ($imgBlur, $this->workingImage, 0, 0, 1, 0, $w - 1, $h); // left
imagecopymerge ($imgBlur, $this->workingImage, 1, 0, 0, 0, $w, $h, 50); // right
imagecopymerge ($imgBlur, $this->workingImage, 0, 0, 0, 0, $w, $h, 50); // center
imagecopy ($imgCanvas, $imgBlur, 0, 0, 0, 0, $w, $h);
imagecopymerge ($imgBlur, $imgCanvas, 0, 0, 0, 1, $w, $h - 1, 33.33333 ); // up
imagecopymerge ($imgBlur, $imgCanvas, 0, 1, 0, 0, $w, $h, 25); // down
}
}
if($sharpenThreshold>0){
// Calculate the difference between the blurred pixels and the original
// and set the pixels
for ($x = 0; $x < $w-1; $x++) { // each row
for ($y = 0; $y < $h; $y++) { // each pixel
$rgbOrig = ImageColorAt($this->workingImage, $x, $y);
$rOrig = (($rgbOrig >> 16) & 0xFF);
$gOrig = (($rgbOrig >> 8) & 0xFF);
$bOrig = ($rgbOrig & 0xFF);
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
$rBlur = (($rgbBlur >> 16) & 0xFF);
$gBlur = (($rgbBlur >> 8) & 0xFF);
$bBlur = ($rgbBlur & 0xFF);
// When the masked pixels differ less from the original
// than the threshold specifies, they are set to their original value.
$rNew = (abs($rOrig - $rBlur) >= $sharpenThreshold) ? max(0, min(255, ($sharpenAmount * ($rOrig - $rBlur)) + $rOrig)) : $rOrig;
$gNew = (abs($gOrig - $gBlur) >= $sharpenThreshold) ? max(0, min(255, ($sharpenAmount * ($gOrig - $gBlur)) + $gOrig)) : $gOrig;
$bNew = (abs($bOrig - $bBlur) >= $sharpenThreshold) ? max(0, min(255, ($sharpenAmount * ($bOrig - $bBlur)) + $bOrig)) : $bOrig;
if (($rOrig != $rNew) || ($gOrig != $gNew) || ($bOrig != $bNew)) {
$pixCol = ImageColorAllocate($this->workingImage, $rNew, $gNew, $bNew);
ImageSetPixel($this->workingImage, $x, $y, $pixCol);
}
}
}
}
else {
for ($x = 0; $x < $w; $x++) { // each row
for ($y = 0; $y < $h; $y++) { // each pixel
$rgbOrig = ImageColorAt($this->workingImage, $x, $y);
$rOrig = (($rgbOrig >> 16) & 0xFF);
$gOrig = (($rgbOrig >> 8) & 0xFF);
$bOrig = ($rgbOrig & 0xFF);
$rgbBlur = ImageColorAt($imgBlur, $x, $y);
$rBlur = (($rgbBlur >> 16) & 0xFF);
$gBlur = (($rgbBlur >> 8) & 0xFF);
$bBlur = ($rgbBlur & 0xFF);
$rNew = ($sharpenAmount * ($rOrig - $rBlur)) + $rOrig;
if($rNew>255){$rNew=255;}
elseif($rNew<0){$rNew=0;}
$gNew = ($sharpenAmount * ($gOrig - $gBlur)) + $gOrig;
if($gNew>255){$gNew=255;}
elseif($gNew<0){$gNew=0;}
$bNew = ($sharpenAmount * ($bOrig - $bBlur)) + $bOrig;
if($bNew>255){$bNew=255;}
elseif($bNew<0){$bNew=0;}
$rgbNew = ($rNew << 16) + ($gNew <<8) + $bNew;
ImageSetPixel($this->workingImage, $x, $y, $rgbNew);
}
}
}
imagedestroy($imgCanvas);
imagedestroy($imgBlur);
// return $this->workingImage;
}
} |
Ilmselt on lahendus väga lihtne, ise lihtsalt ei jaga seda asja üldse
|
|
Kommentaarid: 4 loe/lisa |
Kasutajad arvavad: |
   |
:: |
0 :: |
0 :: |
4 |
|
tagasi üles |
|
 |
DoS
HV veteran

liitunud: 19.08.2002
|
25.01.2010 05:44:01
|
|
|
see teravustaja funktsioon on sul hetkel mingist klassist pärit ja päris üksinda ta nii ei toimi.
aga näiteks siit http://vikjavev.no/computing/ump.php saad sama funktsiooni, mis töötab ka standalonena
ning siis ilmselt pärast rida
imagecopyresampled( $newimage, $image, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); |
kirjutad
$newimage = UnsharpMask($newimage, $amount, $radius, $threshold); |
kus kolm viimast parameetrit on su enda määratud.
|
|
Kommentaarid: 50 loe/lisa |
Kasutajad arvavad: |
   |
:: |
0 :: |
0 :: |
47 |
|
tagasi üles |
|
 |
h2rra
HV vaatleja
liitunud: 04.11.2008
|
25.01.2010 12:53:31
|
|
|
Tänks, sain tööle!
|
|
Kommentaarid: 4 loe/lisa |
Kasutajad arvavad: |
   |
:: |
0 :: |
0 :: |
4 |
|
tagasi üles |
|
 |
|
lisa lemmikuks |
|
|
sa ei või postitada uusi teemasid siia foorumisse sa ei või vastata selle foorumi teemadele sa ei või muuta oma postitusi selles foorumis sa ei või kustutada oma postitusi selles foorumis sa ei või vastata küsitlustele selles foorumis sa ei saa lisada manuseid selles foorumis sa võid manuseid alla laadida selles foorumis
|
|
Hinnavaatlus ei vastuta foorumis tehtud postituste eest.
|