Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 25... Línea 25...
25
 */
25
 */
Línea 26... Línea 26...
26
 
26
 
Línea 27... Línea 27...
27
defined('MOODLE_INTERNAL') || die();
27
defined('MOODLE_INTERNAL') || die();
28
 
-
 
29
/**
-
 
30
 * Copies a rectangular portion of the source image to another rectangle in the destination image
-
 
31
 *
-
 
32
 * This function calls imagecopyresampled() if it is available and GD version is 2 at least.
-
 
33
 * Otherwise it reimplements the same behaviour. See the PHP manual page for more info.
-
 
34
 *
-
 
35
 * @link http://php.net/manual/en/function.imagecopyresampled.php
-
 
36
 * @param resource|\GdImage $dst_img the destination GD image resource
-
 
37
 * @param resource|\GdImage $src_img the source GD image resource
-
 
38
 * @param int $dst_x vthe X coordinate of the upper left corner in the destination image
-
 
39
 * @param int $dst_y the Y coordinate of the upper left corner in the destination image
-
 
40
 * @param int $src_x the X coordinate of the upper left corner in the source image
-
 
41
 * @param int $src_y the Y coordinate of the upper left corner in the source image
-
 
42
 * @param int $dst_w the width of the destination rectangle
-
 
43
 * @param int $dst_h the height of the destination rectangle
-
 
44
 * @param int $src_w the width of the source rectangle
-
 
45
 * @param int $src_h the height of the source rectangle
-
 
46
 * @return ?bool tru on success, false otherwise
-
 
47
 */
-
 
48
function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h) {
-
 
49
    global $CFG;
-
 
50
 
-
 
51
    if (function_exists('imagecopyresampled')) {
-
 
52
       return imagecopyresampled($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y,
-
 
53
                                 $dst_w, $dst_h, $src_w, $src_h);
-
 
54
    }
-
 
55
 
-
 
56
    $totalcolors = imagecolorstotal($src_img);
-
 
57
    for ($i=0; $i<$totalcolors; $i++) {
-
 
58
        if ($colors = imagecolorsforindex($src_img, $i)) {
-
 
59
            imagecolorallocate($dst_img, $colors['red'], $colors['green'], $colors['blue']);
-
 
60
        }
-
 
61
    }
-
 
62
 
-
 
63
    $scalex = ($src_w - 1) / $dst_w;
-
 
64
    $scaley = ($src_h - 1) / $dst_h;
-
 
65
 
-
 
66
    $scalex2 = $scalex / 2.0;
-
 
67
    $scaley2 = $scaley / 2.0;
-
 
68
 
-
 
69
    for ($j = 0; $j < $dst_h; $j++) {
-
 
70
        $sy = $j * $scaley;
-
 
71
 
-
 
72
        for ($i = 0; $i < $dst_w; $i++) {
-
 
73
            $sx = $i * $scalex;
-
 
74
 
-
 
75
            $c1 = imagecolorsforindex($src_img, imagecolorat($src_img, (int)$sx, (int)$sy + $scaley2));
-
 
76
            $c2 = imagecolorsforindex($src_img, imagecolorat($src_img, (int)$sx, (int)$sy));
-
 
77
            $c3 = imagecolorsforindex($src_img, imagecolorat($src_img, (int)$sx + $scalex2, (int)$sy + $scaley2));
-
 
78
            $c4 = imagecolorsforindex($src_img, imagecolorat($src_img, (int)$sx + $scalex2, (int)$sy));
-
 
79
 
-
 
80
            $red = (int) (($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
-
 
81
            $green = (int) (($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
-
 
82
            $blue = (int) (($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);
-
 
83
 
-
 
84
            $color = imagecolorclosest($dst_img, $red, $green, $blue);
-
 
85
            imagesetpixel($dst_img, $i + $dst_x, $j + $dst_y, $color);
-
 
86
        }
-
 
87
    }
-
 
88
}
-
 
89
 
28
 
90
/**
29
/**
91
 * Stores optimised icon images in icon file area.
30
 * Stores optimised icon images in icon file area.
92
 *
31
 *
93
 * Since 2.9 this function will generate an icon in the same format as the original file when possible.
32
 * Since 2.9 this function will generate an icon in the same format as the original file when possible.
Línea 223... Línea 162...
223
        $half = floor($image->width / 2.0);
162
        $half = floor($image->width / 2.0);
224
    } else {
163
    } else {
225
        $half = floor($image->height / 2.0);
164
        $half = floor($image->height / 2.0);
226
    }
165
    }
Línea 227... Línea 166...
227
 
166
 
228
    imagecopybicubic($im1, $im, 0, 0, $cx - $half, $cy - $half, 100, 100, $half * 2, $half * 2);
167
    imagecopyresampled($im1, $im, 0, 0, $cx - $half, $cy - $half, 100, 100, $half * 2, $half * 2);
229
    imagecopybicubic($im2, $im, 0, 0, $cx - $half, $cy - $half, 35, 35, $half * 2, $half * 2);
168
    imagecopyresampled($im2, $im, 0, 0, $cx - $half, $cy - $half, 35, 35, $half * 2, $half * 2);
Línea 230... Línea 169...
230
    imagecopybicubic($im3, $im, 0, 0, $cx - $half, $cy - $half, 512, 512, $half * 2, $half * 2);
169
    imagecopyresampled($im3, $im, 0, 0, $cx - $half, $cy - $half, 512, 512, $half * 2, $half * 2);
Línea 231... Línea 170...
231
 
170
 
Línea 388... Línea 327...
388
        }
327
        }
389
    } else {
328
    } else {
390
        $newimage = imagecreate($canvaswidth, $canvasheight);
329
        $newimage = imagecreate($canvaswidth, $canvasheight);
391
    }
330
    }
Línea 392... Línea 331...
392
 
331
 
Línea 393... Línea 332...
393
    imagecopybicubic($newimage, $original, $dstx, $dsty, 0, 0, $targetwidth, $targetheight, $originalwidth, $originalheight);
332
    imagecopyresampled($newimage, $original, $dstx, $dsty, 0, 0, $targetwidth, $targetheight, $originalwidth, $originalheight);
394
 
333
 
395
    if ($imagefnc === 'imagejpeg') {
334
    if ($imagefnc === 'imagejpeg') {
396
        // Function imagejpeg() accepts less arguments than imagepng() but we need to make $imagefnc accept the same
335
        // Function imagejpeg() accepts less arguments than imagepng() but we need to make $imagefnc accept the same