SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    smarty templates and GD

    I have an image resizing script which uses GD. I'd like to incorporate this into my smarty template layout, but it's causing problems. In a normal page, I'd just do something like:

    <IMG SRC="resize_image.php?image=$story[picture]">

    And that's been working on normal PHP pages where $story[picture] is a databased value like "pictures/424.jpg".

    So now that I'm using a smarty template, if I want to run the resize_image.php script I have to bracket it -

    {php}
    resize_image.php
    {/php}

    like that...

    The problem is that I need to be able to feed resize_image.php a value from the database so it knows what picture to resize. I've tried all sorts of stuff including sending "{php}resize_image.php{/php}" to the template as one big value. The way it compiles it just doesn't seem to work.

    In the simplest terms, the problem here is with a script which must be included into a template and fed by dynamic data. Anyone know how to go about this?

    thanks.

    ian
    signature

  2. #2
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    why not use:

    <IMG SRC="resize_image.php?image={$story.picture}">

    It will work the same way as your other example, assuming you assign( 'story' )
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  3. #3
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried that - the problem is that you have to bracket that as {php} to use it within the template, which nullifies the value of {$story.picture}, or rather produces an error - mixing template elements and PHP apparently being a bad thing.

    ian
    signature

  4. #4
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not show me your template file, and your php that your using to generate it ( assign statements and such )
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us

  5. #5
    SitePoint Zealot
    Join Date
    Sep 2001
    Location
    San Francisco
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks - here's the code pretty much

    resize_image.php consists of, as the name hints, a resizing script that i have been passing variables to with an appended string 'resize_image.php?image=pictures/434.jpg':

    PHP Code:
    if (!$max_width)
      
    $max_width 120;
    if (!
    $max_height)
      
    $max_height 120;

    $size GetImageSize($image);
    $width $size[0];
    $height $size[1];

    $x_ratio $max_width $width;
    $y_ratio $max_height $height;

    if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
      
    $tn_width $width;
      
    $tn_height $height;
    }
    else if ((
    $x_ratio $height) < $max_height) {
      
    $tn_height ceil($x_ratio $height);
      
    $tn_width $max_width;
    }
    else {
      
    $tn_width ceil($y_ratio $width);
      
    $tn_height $max_height;
    }

    $src ImageCreateFromJPEG($image);
    $dst ImageCreate($tn_width,$tn_height);
    ImageCopyResized($dst$src0000,
        
    $tn_width,$tn_height,$width,$height);
    header("Content-type: image/jpeg");
    ImageJPEG($dst);
    ImageDestroy($src);
    ImageDestroy($dst); 
    so my trouble is how to append it dynamically within the smarty template: I'd like to do something like:

    <img src = resize_image.php?image={$main.picture}>

    but to include php like that in the smarty template you need to bracket it with either {include_php} or {php} the problem is then that if you're calling what's inside those brackets php, {$main.picture} can no longer be processed as a template variable.

    I've tried to get the thing to compile on the php page and output <img src = resize_image.php?image={$main.picture}> with the picture inserted dynamically into the template file - doesn't seem to work. Don't know if there's a way of doing this but I'd be massively thankful for any kind of solution.

    thanks!
    signature

  6. #6
    Ribbit... Eric.Coleman's Avatar
    Join Date
    Jun 2001
    Location
    In your basement
    Posts
    1,268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    {$main.picture} is a smarty varable!

    You would assign like this:

    $smarty->assign( 'main', array( 'picture' => 'images/424.gif' ) );
    Eric Coleman
    We're consentratin' on fallin' apart
    We were contenders, now throwin' the fight
    I just wanna believe, I just wanna believe in us


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •