Jump to content

insert code question..


cowboysdude

Recommended Posts

I am showing Youtube videos on my site and am pulling the data in from an xml file... However this is the problem I'm having...

 

When I pull in the video the output is working correctly until you get the image file... it's HUGE...  NOT what I wanted so I set about trying to figure out how to resize the image... I have tried many things but no luck. I don't have access to the google api to change the picture size sooooo... I"m trying to do so within the php I do have..here is what I have...

 

$videos[$i]['img'] = $matches[0];

 

That output shows the HUGE picture....

 

Here is what I've tried to do ...

 

$videos[$i]['img'] = $matches[0] "width=100px height=100px";

 

 

That is a no go... it crashes the site and I know it's a quote thing..  I do know that the first example outputs the image... or puts the img in a string to be output according to the video, I understand that.  How do I resize the img to make it smaller?

 

Here is the entire code for the parsing of the xml file.... 

 

<head>

<link rel="stylesheet" href="modules/mod_jusertube/css/mediaboxAdvBlack21.css" type="text/css" media="screen" />

<script src="modules/mod_jusertube/js/mootools-more-1.3.js" type="text/javascript"></script> 
<script src="modules/mod_jusertube/js/mediaboxAdv-1.4.0.js" type="text/javascript"></script>
<script src="modules/mod_jusertube/js/an7effects-1.5.5.js" type="text/javascript"></script>

</head>

<?php
/**
* @Copyright Copyright (C) 2010- Md. Afzal Hossain
* @license GNU/GPL http://www.gnu.org/copyleft/gpl.html
**/

/*
This file is part of mod_lcc.

    mod_lcc is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    mod_lcc is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with mod_lcc.  If not, see <http://www.gnu.org/licenses/>.

*/
// no direct access
defined('_JEXEC') or die('Restricted access');

class FeedReader
{
    var $cachetime;
var $filepath;


function __construct($updatefeed = 300){
	$this->cachetime = $updatefeed;
	$this->filepath = dirname(__FILE__).DS;
}

function get_youtube_top($youtubeuser,$totalvid){
        $filename = $this->filepath.'youtube_'.$youtubeuser.'.xml';
        if(is_file($filename)){
            $utime = filemtime($filename);
            $chtime = time() - 60*$this->cachetime;
            if($utime>$chtime) $updated = true;
            else $updated = false;
        }
        else{
            $updated = false;
        }
        if(!$updated){
	    $link="http://gdata.youtube.com/feeds/base/users/$youtubeuser/uploads?alt=rss";
	    $ch = curl_init($link);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            $data = curl_exec($ch);
            curl_close($ch);
            if(strlen($data)>100) file_put_contents($filename,$data);
        }
        
        if(is_file($filename)){
            $data = file_get_contents($filename);
        }
        else{
            return false;
        }

	$rss = new SimpleXMLElement($data);
	$i = 0;
        $videos = array();
	foreach($rss->channel->item as $item){
            //$guid_split = explode('/',$item->guid);
            //$videos[$i]['id'] = $guid_split[6];
            $videos[$i]['title'] = (string) $item->title;
            $videos[$i]['link'] = (string) $item->link;
            //$videos[$i]['embed'] = '<object width="100" height="125"><param name="movie" value="http://www.youtube.com/watch/'.$guid_split[6].'"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="http://www.youtube.com/v/'.$guid_split[6].'" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="385"></object>';
            
            $description = (string) $item->description;
            $matches = array();
            preg_match("/<img[^<>]+>/",$description,$matches);
            $videos[$i]['img'] = $matches[0];
		$i++;
		if($i>=$totalvid) break;
	}
	return $videos;
}
    
}

 

Thanks guys!! Again!

Link to comment
Share on other sites

Why does

$videos[$i]['img'] = $matches[0] "width=100px height=100px";

 

Have no concatenation element?

 

$videos[$i]['img'] = $matches[0]."width=100px height=100px";

 

Does that help at all? Because running the first one through PHP will cause an error regardless.

Link to comment
Share on other sites

It runs but does not return the results I was hoping.  I guess I'm just not getting it because I cannot seem to resize that picture down to the size I want.. it just keeps returning with the huge picture from xml...

 

At least now it's returning this...

 

<img alt="" src="http://i.ytimg.com/vi/xxwxMX7doDU/0.jpg">width=100px height=100px

 

Which is getting the sizes in there, just not in the correct place to be recognized.

 

SO here is the line as it is now [Thank you for the help!] but I need to move the width, height into the brackets somehow ....

 

$videos[$i]['img'] = $matches[0]."width=100px height=100px";

 

WOW I am just brain dead on this one... I am having a rough time LOL

Link to comment
Share on other sites

Would this help you at all.

 

instead of squishing the pic try this

$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
$width = intval($ratio*$width);
$height = intval($ratio*$height);

 

as for hyperlinking or displaying an image this way is easy

echo "<a href='$href_location'><img src='$img_src' WIDTH='$width' HEIGHT='$height' border='0'></a><br/>";

Link to comment
Share on other sites

It runs but does not return the results I was hoping.  I guess I'm just not getting it because I cannot seem to resize that picture down to the size I want.. it just keeps returning with the huge picture from xml...

 

At least now it's returning this...

 

<img alt="" src="http://i.ytimg.com/vi/xxwxMX7doDU/0.jpg">width=100px height=100px

 

Which is getting the sizes in there, just not in the correct place to be recognized.

 

SO here is the line as it is now [Thank you for the help!] but I need to move the width, height into the brackets somehow ....

 

$videos[$i]['img'] = $matches[0]."width=100px height=100px";

 

WOW I am just brain dead on this one... I am having a rough time LOL

 

I agree with quickoldcar, in general I've found it better to just save the URL location of the image so you can format it however afterwards. Though for your case this would probably work as well:

$videos[$i]['img'] = str_replace(">", "width=100px height=100px", $matches[0]);

 

However, as width/height attributes in an img tag, pixels don't need to specified I believe, that's more of a css thing. I could be wrong though.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.