Welcome Guest, Not a member yet? Register   Sign In
trouble with GD, gibberish output...
#1

[eluser]unsub[/eluser]
Hello,

I have attempted to make a Helper out of the image corner rounding code from here:
http://www.assemblysys.com/dataServices/...orners.php

I'm on the beginner side of intermediate, so my results may be ugly... don't look directly at my code for too long if you have sensitive eyes Wink

Also not experienced at all with GD... but caveats aside, here is my result:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('round_img'))
{
    function round_img($images_dir,$image_file,$corner_radius=NULL,$angle=0,$topleft=NULL,$bottomleft=NULL,$bottomright=NULL,$topright=NULL)
    {        
        $angle = 0; // The default angle is set to 0ยบ
        $topleft = (!$topleft) ? false : true; // Top-left rounded corner is shown by default
        $bottomleft = (!$bottomleft) ? false : true; // Bottom-left rounded corner is shown by default
        $bottomright = (!$bottomright) ? false : true; // Bottom-right rounded corner is shown by default
        $topright = (!$topright) ? false : true; // Top-right rounded corner is shown by default
        $corner_radius = $corner_radius == NULL ? 10 : $corner_radius;
        
        $round_src = "utility/rounded_corner_10px.png";
        $corner_source = imagecreatefrompng($images_dir.$round_src);
        
        $corner_width = imagesx($corner_source);  
        $corner_height = imagesy($corner_source);  
        $corner_resized = ImageCreateTrueColor($corner_radius, $corner_radius);
        ImageCopyResampled($corner_resized, $corner_source, 0, 0, 0, 0, $corner_radius, $corner_radius, $corner_width, $corner_height);
        
        $corner_width = imagesx($corner_resized);  
        $corner_height = imagesy($corner_resized);  
        $image = imagecreatetruecolor($corner_width, $corner_height);  
        $image = imagecreatefromjpeg($image_file); // replace filename with $_GET['src']
        $size = getimagesize($image_file); // replace filename with $_GET['src']
        $white = ImageColorAllocate($image,255,255,255);
        $black = ImageColorAllocate($image,0,0,0);

        // Top-left corner
        if ($topleft == true) {
            $dest_x = 0;  
            $dest_y = 0;  
            imagecolortransparent($corner_resized, $black);
            imagecopymerge($image, $corner_resized, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);
        }
        
        // Bottom-left corner
        if ($bottomleft == true) {
            $dest_x = 0;  
            $dest_y = $size[1] - $corner_height;
            $rotated = imagerotate($corner_resized, 90, 0);
            imagecolortransparent($rotated, $black);
            imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
        }
        
        // Bottom-right corner
        if ($bottomright == true) {
            $dest_x = $size[0] - $corner_width;  
            $dest_y = $size[1] - $corner_height;  
            $rotated = imagerotate($corner_resized, 180, 0);
            imagecolortransparent($rotated, $black);
            imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
        }
        
        // Top-right corner
        if ($topright == true) {
            $dest_x = $size[0] - $corner_width;  
            $dest_y = 0;  
            $rotated = imagerotate($corner_resized, 270, 0);
            imagecolortransparent($rotated, $black);
            imagecopymerge($image, $rotated, $dest_x, $dest_y, 0, 0, $corner_width, $corner_height, 100);  
        }
        
        // Rotate image
        $image = imagerotate($image, $angle, $white);
        
        // Output final image
        
        return imagejpeg($image);
        imagedestroy($image);  
        imagedestroy($corner_source);
    }  
}



?>
I load the helper ($this->load->helper('round')Wink in the controller, then call it in the view like so, and much like the original code example from that page (as the src attr. of the img tag):
Code:
src="<?php round_img($this->config->item('unsub_images'),$this->config->item('home_pics').'thumb_'.$blog['image']);?>"

Now the problem... Instead of getting the nice rounded corners on my thumbnail, I get a huge, 150 line string of wierd symbols. Looks like some kind of alien language. I'm sure it's a mchine code of some kind, but I don't recognize it.

I have used this function before in non-CI sites, and it works nicely.

So... I'm not looking for help re-writing this, or anything. I am just hoping maybe I can get an explanation of what the strange symbols are, and if there is anything really glaring in my helper, maybe some pointers on that? And if this is just too ugly and I should try something else, please let me know. I can deal Smile haha

GD is installed, I did a vars dump at one point, and everything I was trying to do is set to true, so I'm lost.

Cheers, and thanks for any advice on this.
-gabriel




Theme © iAndrew 2016 - Forum software by © MyBB