ID:835739
 
Keywords: jpeg, jpg
(See the best response by Lummox JR.)
When attempting to download, scale, and display JPEG's on a skin in this topic...
http://www.byond.com/forum/?post=832426

... I was very confused why the icon would display, but would crash when using any of the icon proc's (Scale, Insert, etc.).

Then I realized that it can only do those operations on PNG's.

Can BYOND get support for icon proc's on JPEG images (in particular, Scale)?
Using jpegs/jpgs works fine for me, when using scale. Since I wrote the procedure you're using, I don't know what's up.

This works fine for me in all cases, jpegs or not:
proc/GetImage(link,scale)
var/img[] = world.Export(link)
if(img && findtext(img["CONTENT-TYPE"], "image"))
var/icon/img2 = icon(img["CONTENT"])
if(scale)
img2.Scale(img2.Width()*scale, img2.Height()*scale)
//or img2.Scale(scale,scale)
return img2

mob/verb/change_icon(link as text, scale as num)
icon = GetImage("[link]", scale)

mob/verb/http2img(link as text, scale as num, control as text)
winset(src, "[control]", "image=\ref[fcopy_rsc(GetImage(link,scale))]")
Best response
Internally BYOND doesn't care if the image started as a JPEG or not. Once it's been loaded, it has become an icon and can be manipulated via the /icon procs.

If you're experiencing a crash, the cause is something else. It could well be related to the specific image you're trying to work with, or something more. If it's a hard crash (actually killing DS/DD itself) then that's a bug, and if it's a proc crash it could be a bug or an issue in your code. However we would need more information to be sure.

The only clear thing at this point is that this is not a feature issue, since the feature already exists, so for the time being I'll move it to Developer Help.
I guess this is PEBCAK, but apparently the images were being sent back by an ASP page. The site was not directly sending back an image, the HTTP request went through an ASP page, and ASP sent back an image.

There's something either subtly weird in the HTTP header response or the image itself, but I couldn't operate on that image.

The Scale proc would crash with the error message:
runtime error: bad icon operation
proc name: New (/icon/New)
usr: Guest-1674280161 (/mob/player)
src: /icon (/icon)
call stack:
/icon (/icon): New('Image.ashx', null, null, null, null)

Huh, that's strange. I found a "ashx" file, which is just a jpeg internally.
It seems that only icon() (or icon/new) has an issue with it.

proc/GetImage(link,scale)
var/img[] = world.Export(link)
if(img&&findtext(img["CONTENT-TYPE"],"image"))
var/img2 = img["CONTENT"]
return img2

This works fine. When you output it onto the map, output control, or as an image in an interface control, it works fine.

However, it's only when you try to turn it an icon via
var/icon/img2 = icon(content) that it gives an error, the one Mardock posted. If you exclude icon() it gives no error...until you try to use an icon operation, because then it sees the icon as null.
I found a new problem:

proc/GetImage(link)
var/img[] = world.Export(link)
if(img && findtext(img["CONTENT-TYPE"], "image"))
var/icon/img2 = icon(img["CONTENT"])
//if(scale)
//img2.Scale(img2.Width()*scale, img2.Height()*scale)
//or img2.Scale(scale,scale)
//Instead of scaling, we'll turn the image instead
img2.Turn(90)
return img2

mob/verb/change_icon(link as text, scale as num)
icon = GetImage("[link]", scale)

mob/verb/http2img(link as text, scale as num, control as text)
winset(src, "[control]", "image=\ref[fcopy_rsc(GetImage(link,scale))]")


There are no error messages, and the icon displays, but it isn't turned 90 degrees like it should.
Is the image a square?
Turn doesn't work unless the icon is a perfect square. (Width and height are equal)