Solved

using a variable with getimagesize()

Posted on 2009-05-18
5
603 Views
Last Modified: 2013-12-12
I'm trying to get image size so I can make a thumbnail on the fly, the path to the image is kept in a database and the image is in one of many folders. the path saved in the db has the html tag so basically
<img src="http://www.domain.com/folder/subfolder/subfolder/imagename.jpg">

I'm using str_replace to remove the <img src= and > from the string and I assign the result to a variable ($img)

than I'm trying to use getimagesize($img); but I get this error message

getimagesize("http://www.domain.com/folder/subfolder/subfolder/imagename.jpg") [function.getimagesize]: failed to open stream: No such file or directory

the thing is if I hardcode the path instead of using the variable it work fine.

Anybody know why and how to make it work with a variable?
0
Comment
Question by:gamebits
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24417585
Show us the code, please.
0
 
LVL 28

Author Comment

by:gamebits
ID: 24417600
<?php
error_reporting(E_ALL);
$originalString = '<img src="http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg">';
$newString = str_replace("<img src=","",$originalString);
$newnewString = str_replace(">","",$newString);

$info = getimagesize("$newnewString") ;

//print_r($info);

$width = $info[0];
$height= $info[1];

  $width = $width/3;
  $height = $height/3;
 
echo "<a href=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\"><img src=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\" width=\"$width\" height=\"$height\" border=0></a>";

?>

originalstring will be pulled from database query
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 24417636
This worked for me.  Note that I had to modify the str_replace at lines 6 and 7 to take out the double quotes.

HTH, ~Ray
<?php // RAY_temp_gamebits.php
error_reporting(E_ALL);
echo "<pre>\n";
 
$originalString = '<img src="http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg">';
$newString = str_replace('<img src="',"",$originalString);
$newnewString = str_replace('">',"",$newString);
 
$info = getimagesize($newnewString) ;
var_dump($newnewString);
var_dump($info);
 
$width = $info[0];
$height= $info[1];
 
  $width = $width/3;
  $height = $height/3;
 
echo "<a href=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\"><img src=\"http://www.cemond.com/Trading_Cards/Topps/Zorro_1958/2f.jpg\" width=\"$width\" height=\"$height\" border=0></a>";

Open in new window

0
 
LVL 28

Author Closing Comment

by:gamebits
ID: 31582823
Thank you sir, appreciated.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 24417667
Thanks for the points - glad we could shoot this one down quickly!  Best, ~Ray
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question