Make WordPress Core

Changeset 4401


Ignore:
Timestamp:
10/16/2006 06:06:18 AM (20 years ago)
Author:
matt
Message:

Some helper functions for themes and images

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-functions.php

    r4388 r4401  
    20742074add_action('update_option_siteurl', 'update_home_siteurl', 10, 2);
    20752075
     2076function wp_crop_image($src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false) {
     2077        if ( ctype_digit($src_file) ) // Handle int as attachment ID
     2078                $src_file = get_attached_file($src_file);
     2079
     2080        $src = wp_load_image($src_file);
     2081
     2082        if ( !is_resource($src) )
     2083                return $src;
     2084
     2085        $dst = imagecreatetruecolor($dst_w, $dst_h);
     2086
     2087        if ( $src_abs ) {
     2088                $src_w -= $src_x;
     2089                $src_h -= $src_y;
     2090        }
     2091
     2092        imageantialias($dst, true);
     2093        imagecopyresampled($dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h);
     2094
     2095        if ( !$dst_file )
     2096                $dst_file = str_replace(basename($src_file), 'cropped-'.basename($src_file), $src_file);
     2097
     2098        $dst_file = preg_replace('/\\.[^\\.]+$/', '.jpg', $dst_file);
     2099
     2100        if ( imagejpeg($dst, $dst_file) )
     2101                return $dst_file;
     2102        else
     2103                return false;
     2104}
     2105
     2106function wp_load_image($file) {
     2107        if ( ctype_digit($file) )
     2108                $file = get_attached_file($file);
     2109
     2110        if ( !file_exists($file) )
     2111                return "File '$file' doesn't exist?";
     2112
     2113        $contents = file_get_contents($file);
     2114
     2115        $image = imagecreatefromstring($contents);
     2116
     2117        if ( !is_resource($image) )
     2118                return "File '$file' is not image?";
     2119
     2120        return $image;
     2121}
     2122
    20762123?>
  • trunk/wp-includes/theme.php

    r4400 r4401  
    428428}
    429429
     430function get_theme_mod($name, $default = false) {
     431        $theme = get_current_theme();
     432
     433        $mods = get_option("mods_$theme");
     434
     435        if ( isset($mods[$name]) )
     436                return $mods[$name];
     437
     438        return sprintf($default, get_template_directory_uri());
     439}
     440
     441function set_theme_mod($name, $value) {
     442        $theme = get_current_theme();
     443
     444        $mods = get_option("mods_$theme");
     445
     446        $mods[$name] = $value;
     447
     448        update_option("mods_$theme", $mods);
     449        wp_cache_delete("mods_$theme", 'options');
     450}
     451
     452function remove_theme_mods() {
     453        $theme = get_current_theme();
     454
     455        delete_option("mods_$theme");
     456}
     457
    430458?>
Note: See TracChangeset for help on using the changeset viewer.